title: Mail form Ajax validation not working
body: <p>I am using a simple HTML form with an ajax validation, and php to mail, however It keeps giving me the error that the message was not sent. If I disable the ajax the form will go through. What can I do to fix this issue?</p>
  
  <p>HTML form:</p>
  
  <pre><code>&lt;form method="POST" action="/tj/send.php"&gt;
                                                      &lt;p&gt;
                                                          &lt;label for="name"&gt;Name &lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt;
                                                          &lt;input type="text" name="name" id="name"&gt;
                                                      &lt;/p&gt;
                                                      &lt;p&gt;
                                                          &lt;label for="email"&gt;Email &lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt;
                                                          &lt;input type="text" name="email" id="email"&gt;
                                                      &lt;/p&gt;
                                                      &lt;p&gt;
                                                          &lt;label for="subject"&gt;Subject&lt;/label&gt;
                                                          &lt;input type="text" name="subject" id="subject"&gt;
                                                      &lt;/p&gt;
                                                      &lt;p&gt;
                                                          &lt;label for="subject"&gt;Message &lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt;
                                                          &lt;textarea name="message" id="message" cols="45" rows="10"&gt;&lt;/textarea&gt;
                                                      &lt;/p&gt;
                                                      &lt;div class="fBtn"&gt;
                                                          &lt;button type="submit" name="submit" id="submit" class="regButton"&gt;&lt;i class="icon-paper-plane"&gt;&lt;/i&gt;Send Message&lt;/button&gt;
                                                      &lt;/div&gt;
                                                  &lt;/form&gt;
                              &lt;div id="success"&gt;&lt;h2&gt;Your message has been sent. Thank you!&lt;/h2&gt;&lt;/div&gt;
                          &lt;div id="error"&gt;&lt;h2&gt;Sorry your message can not be sent.&lt;/h2&gt;&lt;/div&gt;
                                          &lt;/div&gt;          
  </code></pre>
  
  <p>AJAX Validation:</p>
  
  <pre><code>$('#submit').click(function(){ 
  
  $('input#name').removeClass("errorForm");
  $('textarea#message').removeClass("errorForm");
  $('input#email').removeClass("errorForm");
  
  var error = false; 
  var name = $('input#name').val(); 
  if(name == "" || name == " ") { 
      error = true; 
      $('input#name').addClass("errorForm");
  }
  
  
      var msg = $('textarea#message').val(); 
      if(msg == "" || msg == " ") {
          error = true;
          $('textarea#message').addClass("errorForm");
  
      }
  
  var email_compare = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i; 
  var email = $('input#email').val(); 
  if (email == "" || email == " ") { 
      $('input#email').addClass("errorForm");
      error = true;
  }else if (!email_compare.test(email)) { 
      $('input#email').addClass("errorForm");
      error = true;
  }
  
  if(error == true) {
      return false;
  }
  
  var data_string = $('.contactForm form').serialize(); 
  
  
  $.ajax({
      type: "POST",
      url: $('.contactForm form').attr('action'),
      data: data_string,
  
      success: function(message) {
                  console.log("AJAX Error:" + message);
              if(message == 'SENDING'){
                  $('#success').fadeIn('slow');
              }
              else{
  
                  $('#error').fadeIn('slow');
              }
                  }
  
  
  
  });
  
  return false; 
  });
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>    &lt;?php
  /* Code by David McKeown - craftedbydavid.com */
  /* Editable entries are bellow */
  $send_to = "pthornt1@gmail.com";
  $send_subject = "trishajohnson.net form";
  
  /*Be careful when editing below this line */
  $name = cleanupentries($_POST["name"]);
  $email = cleanupentries($_POST["email"]);
  $subject = cleanupentries($_POST["subject"]);
  $message = cleanupentries($_POST["message"]);
  $from_ip = $_SERVER['REMOTE_ADDR'];
  $from_browser = $_SERVER['HTTP_USER_AGENT'];
  
  
  
  function cleanupentries($entry) {
      $entry = trim($entry);
      $entry = stripslashes($entry);
      $entry = htmlspecialchars($entry);
      return $entry;
  }
  $message = "This email was submitted on " . date('m-d-Y') . 
  "\n\nName: " . $name .
  "\n\nE-Mail: " . $email . 
  "\n\nMessage: \n" . $message . 
  "\n\n\nTechnical Details:\n" . $from_ip . "\n" . $from_browser;
  $send_subject .= " - {$name}";
  $headers = "From: " . $email . "\r\n" .
      "Reply-To: " . $email . "\r\n" .
      "X-Mailer: PHP/" . phpversion();
  
  /* Send the message using mail() function */
  mail($send_to,$send_subject,$message);
  ?&gt;
  </code></pre>