title: I want this to validate, if no errors to mail out the answers.
body: <p>I am new to php and am helping a non-profit do an exit survey of their volunteers. I have built the following script into the space above my first html tag and can get it to show me on submit when a field is empty but it does not send it if correct the first submit or on resubmission. What am I doing wrong with the MAIL function or is my error array I built wrong? Thank you kindly for your words of advice.</p>
  
  <p>Here is my PHP Code:</p>
  
  <pre><code>&lt;?php
  
  $firstnameErr = $lastnameErr = $Q1Err = $Q2Err = $Q3Err = $Q4Err = $Q5Err = $Q6Err = $Q7Err = $Q8Err = $Q9Err = $Q10Err = $Q11Err = $A1Err = $A2Err = $A3Err = $A4Err = $A5Err = $A6Err = $A7Err = $A8Err = $A9Err = $A10Err = $A11Err = "";
  $firstname = $lastname = $Q1 = $Q2 = $Q3 = $Q4 = $Q5 = $Q6 = $Q7 = $Q8 = $Q9 = $Q10 = $Q11 = $A1 = $A2 = $A3 = $A4 = $A5 = $A6 = $A7 = $A8 = $A9 = $A10 = $A11 = "";
  
  
  if ($_SERVER["REQUEST_METHOD"] == "POST")  {
  
  //Here are the fields it is checking
  
      $firstname = $_POST["firstname"];
      $lastname = $_POST["lastname"];
      $Q1 = $_POST["Q1"];
      $Q2 = $_POST["Q2"];
      $Q3 = $_POST["Q3"];
      $Q4 = $_POST["Q4"];
      $Q5 = $_POST["Q5"];
      $Q6 = $_POST["Q6"];
      $Q7 = $_POST["Q7"];
      $Q8 = $_POST["Q8"];
      $Q9 = $_POST["Q9"];
      $Q10 = $_POST["Q10"];
      $Q11 = $_POST["Q11"];
      $A1 = $_POST["A1"];
      $A2 = $_POST["A2"];
      $A3 = $_POST["A3"];
      $A4 = $_POST["A4"];
      $A5 = $_POST["A5"];
      $A6 = $_POST["A6"];
      $A7 = $_POST["A7"];
      $A8 = $_POST["A8"];
      $A9 = $_POST["A9"];
      $A10 = $_POST["A10"];
      $A11 = $_POST["A11"];
  
  
  //Start of First Name Validation
  
      if (empty($_POST["firstname"])) {   //NOTE: Below is where it will post the error message
          $firstnameErr = "Your first name is required please";
     } 
     else {
          $firstname = $_POST["firstname"];
     }
  
  //Start of Last Name Validation
  
      if (empty($_POST["lastname"])) {
          $lastnameErr = "Your last name is required please";
    } 
    else {
          $lastname = $_POST["lastname"];
    }
  
  //Start of Question 1 Radio Button Validation
  
      if (empty($_POST["Q1"])) {
          $Q1Err = "Please select an answer";
    } 
    else {
          $Q1 = $_POST["Q1"];
    }
  
  //Start of Answer 2 - not actually validating
  
      if (empty($_POST["A1"])) {
          $A1 = "";
    } 
    else {
          $A1 = $_POST["A1"];
    }
  
  //Start of Question 2 Radio Button Validation
  
      if (empty($_POST["Q2"])) {
          $Q2Err = "Please select an answer";
    } 
    else {
          $Q2 = $_POST["Q1"];
    }
  
      if (empty($_POST["A2"])) {
          $A2 = "";
    } 
    else {
          $A2 = $_POST["A2"];
    }  
  
      if (empty($_POST["Q3"])) {
          $Q3Err = "Please select an answer";
    } 
    else {
          $Q3 = $_POST["Q3"];
    }
  
      if (empty($_POST["A3"])) {
          $A3 = "";
    } 
    else {
          $A3 = $_POST["A3"];
    }
  
      if (empty($_POST["Q4"])) {
          $Q4Err = "Please select an answer";
    } 
    else {
          $Q4 = $_POST["Q4"];
    }
      if (empty($_POST["A4"])) {
          $A4 = "";
    } 
    else {
          $A4 = check_input($_POST["A4"]);
    }   
  
      if (empty($_POST["Q5"])) {
          $Q5Err = "Please select an answer";
    } 
    else {
          $Q5 = $_POST["Q5"];
    }
  
      if (empty($_POST["A5"])) {
          $A5 = "";
    } 
    else {
          $A5 = $_POST["A5"];
    }
  
      if (empty($_POST["Q6"])) {
          $Q6Err = "Please select an answer";
    } 
    else {
          $Q6 = $_POST["Q6"];
    }
  
      if (empty($_POST["A6"])) {
          $A6 = "";
    } 
    else {
          $A6 = $_POST["A6"];
    } 
  
      if (empty($_POST["Q7"])) {
          $Q7Err = "Please select an answer";
    } 
    else {
          $Q7 = $_POST["Q7"];
    }
      if (empty($_POST["A7"])) {
          $A7 = "";
    } 
    else {
      $A7 = $_POST["A7"];
    }
  
      if (empty($_POST["Q8"])) {
          $Q8Err = "Please select an answer";
    } 
    else {
          $Q8 = $_POST["Q8"];
    }
  
      if (empty($_POST["A8"])) {
          $A8 = "";
    } 
    else {
          $A8 = $_POST["A8"];
    }   
  
      if (empty($_POST["Q9"])) {
          $Q9Err = "Please select an answer";
    } 
   else {
          $Q9 = $_POST["Q9"];
    }
  
      if (empty($_POST["A9"])) {
          $A9 = "";
    } 
    else {
          $A9 = $_POST["A9"];
    }
  
      if (empty($_POST["Q10"])) {
          $Q10Err = "Please select an answer";
    } 
    else {
          $Q10 = $_POST["Q10"];
    }
  
      if (empty($_POST["A10"])) {
          $A10 = "";
    } 
    else {
          $A10 = $_POST["A10"];
    } 
  
      if (empty($_POST["Q11"])) {
          $Q11Err = "Please select an answer";
    } 
    else {
          $Q11 = $_POST["Q11"];
    }
  
      if (empty($_POST["A11"])) {
          $A11 = "";
    } 
    else {
          $A11 = $_POST["A11"]; 
  }
  
  //Email out results code
  
          if ($firstnameErr == "" &amp;&amp; $lastnameErr == "" &amp;&amp; $Q1Err == "" &amp;&amp; $Q2Err == ""&amp;&amp; $Q3Err == "" &amp;&amp; $Q4Err == "" &amp;&amp; $Q5Err == "" &amp;&amp; $Q6Err == "" &amp;&amp; $Q7Err == "" &amp;&amp; $Q8Err == "" &amp;&amp; $Q9Err == "" &amp;&amp; $Q10Err == "" &amp;&amp; $Q11Err == "")  { 
  
  /* Send the message using mail() function */
          mail($myemail, $subject, $message);{
          $myemail = "anyone@gmail.com";
          $subject = "Exit Survey Completed";
          $message = "Greetings! The Exit Survey you sent out has been completed by: 
  
          First Name: $firstname 
          Last Name: $lastname
  
          Here is what $firstname had to say:
  
          1: Do you like beans? 
          Answer: $Q1
          Explaination, if recorded: $A1
  
          2. Do you like George Wendt?
          Answer: $Q2
          Explaination, if recorded: $A2
  
          3. Would you like to watch a movie about beans?
          Answer: $Q3
          Explaination, if recorded: $A3
  
          4. Would you watch a movie where George Wendt eats beans?
          Answer: $Q4
          Explaination, if recorded: $A4
  
          5. ___ ?
          Answer: $Q5
          Explaination, if recorded: $A5
  
          6. ___ ?
          Answer: $Q6
          Explaination, if recorded: $A6
  
          7. ___ ? 
          Answer: $Q7
          Explaination, if recorded: $A7
  
          8. ___ ? 
          Answer: $Q8
          Explaination, if recorded: $A8
  
          9. Did you feel you received ongoing feedback on your performance?  
          Answer: $Q9
          Explaination, if recorded: $A9
  
          10. Did you feel that the feedback on your performance was presented to you in a 
          sensitive and confidential manner?  
          Answer: $Q10
          Explaination, if recorded: $A10
  
          11. ___?
          Answer: $Q11
          Explaination, if recorded: $A11
  
          Additional Comments by $firstname :
          $comments
  
          Have a great day!
  ______________________________________________________________________________
  
  
  Thank you";
  
  /* Redirect visitor to the thank you page */
  header('Location: thanks.htm');
  exit();
  
          }
    }
  ?&gt;
  </code></pre>