title: PHP mail() vaildation
body: <p>so i'm still relatively new to PHP and have been building a order form that can validate the fields before sending, as well as checking for spam.
  From testing the below code works fine in returning errors and so on, but when I enter correct information I dont get any emails.
  It was working fine before i added the Vaildation part to it but now im getting the problem above. Again i am still learning so any pointers would be nice, thanks </p>
  
  <pre><code>&lt;?php
      function spamcheck($field) {
        $field=filter_var($field, FILTER_SANITIZE_EMAIL);
        if(filter_var($field, FILTER_VALIDATE_EMAIL)) {
          return TRUE;
        } else {
          return FALSE;
        }
      }
      ?&gt;
      &lt;?php
      if (!isset($_POST["submit"])) {
        ?&gt;
  </code></pre>
  
  <p>Form</p>
  
  <pre><code>&lt;?php } 
  else 
  {
      if (isset($_POST["email"])) {
          $mailcheck = spamcheck($_POST["email"]);
          if ($mailcheck==FALSE) {
              echo "Invalid input";
              }
  //field vailation
          else {
              if (isset($_POST['submit'])) {
                  $errors = array();
                  if (!empty($_POST["fullname"])) {
                      $fullname = $_POST["fullname"];
                      $pattern = "/^[a-zA-Z0-9\_]{2,20}/";
                      if (preg_match($pattern,$fullname)){ $fullname = $_POST["fullname"];}
                          else{ $errors[] = 'Your Name can only contain _, 1-9, A-Z or a-z 2-20 long.';}
                          } else {$errors[] = 'You forgot to enter your First Name.';}
  
                  if (!empty($_POST["contact"])) {
                      $contact = $_POST["contact"];
                      $pattern = "/^[0-9\_]{6,20}/";
                      if (preg_match($pattern,$contact)){ $contact = $_POST["contact"];}
                          else{ $errors[] = 'Your contact number can only be numbers, or is too short';}
                          } else {$errors[] = 'You forgot to enter your contact number.';}
              }
  //end vaildation
              else{
                  $fullname = $_POST["fullname"];
                  $email = $_POST["email"];
                  $address = $_POST["address"];
                  $address2 = $_POST["address2"];
                  $town = $_POST["town"];
                  $postcode = $_POST["postcode"];
                  $contact = $_POST["contact"];
                  $shipping = $_POST["shipping"];
                  $extra = $_POST["extra"];
                  $extra = wordwrap($extra, 70);
  
                  $message = '
                  Full Name: ' . $fullname . '
                  Delivery Address: ' . $address . '
                  Delivery Address2: ' . $address2 . '
                  Town/City: ' . $town . '
                  Postal Code: ' . $postcode . '
                  Contact: ' . $contact . '
                  Email Address: ' . $email . '
                  Special instructions: ' . $extra . '
                  Shipping Method: ' . $shipping . '
                  ';
                  mail("myemail@myaddress.com","Order form",$message,"email: $email\n");
                  echo 
                  "&lt;html&gt;
                  &lt;body&gt;&lt;br&gt;&lt;br&gt;
                  Order successful, we will be in contact shortly&lt;br&gt;
                  &lt;/body&gt;
                  &lt;/html&gt;";
              }
          }
      }
  }
  ?&gt;
  
  &lt;?php 
  if (isset($_POST['submit'])) {
      if (!empty($errors)) { 
          echo '&lt;hr /&gt;&lt;h3&gt;The following occurred:&lt;/h3&gt;&lt;ul&gt;'; 
          foreach ($errors as $msg) { echo '&lt;li&gt;'. $msg . '&lt;/li&gt;';}
          echo '&lt;/ul&gt;&lt;h3&gt;Your mail could not be sent due to input errors.&lt;/h3&gt;&lt;hr /&gt;';}
          else{echo 
          "&lt;html&gt;
          &lt;body&gt;&lt;br&gt;&lt;br&gt;
          Order successful, we will be in contact shortly&lt;br&gt;
          &lt;/body&gt;
          &lt;/html&gt;";
      }
  }
  ?&gt;
  </code></pre>
  
  <p>After using <code>error_reporting(E_ALL);</code> ive noticed that im getting an error <code>unexpected 'else' (T_ELSE)</code> for the else at the top of the second block of code, so I tried moving code to : </p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  if (!isset($_POST["submit"])) {
  } 
  
  else 
  {
  </code></pre>
  
  <p>And left the form above this so that when the sumbit button is pressed the forms wont dissapear. Which is not giving me any errors but still not email once submitted</p>