title: Notice: Undefined index: variable
body: <p>I am trying to build the following form:</p>
  
  <pre><code>&lt;form method="post" action="Index.php"&gt;
    &lt;label&gt;Name &lt;/label&gt;
    &lt;input name="name" placeholder="Type Here"&gt;&lt;br /&gt;
    &lt;/br&gt;
    &lt;label&gt;Email &lt;/label&gt;
    &lt;input name="email" placeholder="Type Here"&gt;
    &lt;br /&gt;&lt;/br&gt;
    &lt;label style="display:block;"&gt;I need some information regarding:&lt;/label&gt;
    &lt;textarea name="message" placeholder="Type Here"&gt;&lt;/textarea&gt;
    &lt;br /&gt;
    &lt;label&gt;*What is 2+2? (Anti-spam)&lt;/label&gt;
    &lt;input name="human" placeholder="Type Here"&gt;
    &lt;br /&gt;
    &lt;input id="submit" name="submit" type="submit" value="Submit" style="height:30px;"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The PHP code:</p>
  
  <pre><code>&lt;?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: TangledDemo';
    $to = 'hello@emailaddress.com';
    $subject = 'Hello';
    $human = $_POST['human'];
  
    $body = "From: $name\n E-Mail: $email\n Message:\n $message";
  
    if ($_POST['submit'] &amp;&amp; $human == '4') {
      if (mail ($to, $subject, $body, $from)) {
        echo '&lt;p&gt;Your message has been sent!&lt;/p&gt;';
      } else {
        echo '&lt;p&gt;Something went wrong, go back and try again!&lt;/p&gt;';
      }
    } else if ($_POST['submit'] &amp;&amp; $human != '4') {
      echo '&lt;p&gt;You answered the anti-spam question incorrectly!&lt;/p&gt;';
    }
  
    if ($_POST['submit']) {
      if ($name != '' &amp;&amp; $email != '') {
        if ($human == '4') {
          if (mail ($to, $subject, $body, $from)) {
            echo '&lt;p&gt;Your message has been sent!&lt;/p&gt;';
          } else {
            echo '&lt;p&gt;Something went wrong, go back and try again!&lt;/p&gt;';
          }
        } else if ($_POST['submit'] &amp;&amp; $human != '4') {
          echo '&lt;p&gt;You answered the anti-spam question incorrectly!&lt;/p&gt;';
        }
      } else {
        echo '&lt;p&gt;You need to fill in all required fields!!&lt;/p&gt;';
      }
    }
  ?&gt;
  </code></pre>
  
  <p>But constantly getting these errors:</p>
  
  <blockquote>
    <p>Notice: Undefined index: name in C:\xampp\htdocs\bet4info\Index.php on
    line 19</p>
    
    <p>Notice: Undefined index: email in C:\xampp\htdocs\bet4info\Index.php
    on line 20</p>
    
    <p>Notice: Undefined index: message in C:\xampp\htdocs\bet4info\Index.php
    on line 21</p>
    
    <p>Notice: Undefined index: human in C:\xampp\htdocs\bet4info\Index.php
    on line 25</p>
    
    <p>Notice: Undefined index: submit in C:\xampp\htdocs\bet4info\Index.php
    on line 29</p>
    
    <p>Notice: Undefined index: submit in C:\xampp\htdocs\bet4info\Index.php
    on line 35</p>
    
    <p>Notice: Undefined index: submit in C:\xampp\htdocs\bet4info\Index.php
    on line 38</p>
  </blockquote>
  
  <p>Why is it so?</p>