title: Ajax form sent success but no email
body: <p>I have an <strong>AJAX</strong> form which is saying its successful but still not receiving any emails from this, very annoying. </p>
  
  <pre><code>&lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  
  /*
      Code by David McKeown
      www.craftedbydavid.com
  */
  
  jQuery(document).ready(function () { // wait until the document is ready
      jQuery('#send').click(function(){ // when the button is clicked the code executes
          jQuery('.error').fadeOut('slow'); // reset the error messages (hides them)
  
          var error = false; // we will set this true if the form isn't valid
  
          var name = jQuery('input#name').val(); // get the value of the input field
          if(name == "" || name == " ") {
              jQuery('#err-name').fadeIn('slow'); // show the error message
              error = true; // change the error state to true
          }
  
          var phone = jQuery('input#phone').val(); // get the value of the input field
          if(phone == "" || phone == " ") {
              jQuery('#err-phone').fadeIn('slow'); // show the error message
              error = true; // change the error state to true
          }
  
          var email_compare = /^([a-z0-9_.-]+)@([da-z.-]+).([a-z.]{2,6})$/; // Syntax to compare against input
          var email = jQuery('input#email').val(); // get the value of the input field
          if (email == "" || email == " ") { // check if the field is empty
              jQuery('#err-email').fadeIn('slow'); // error - empty
              error = true;
  
          }else if (!email_compare.test(email)) { // if it's not empty check the format against our email_compare variable
              jQuery('#err-emailvld').fadeIn('slow'); // error - not right format
              error = true;
          }
  
          if(error == true) {
              jQuery('#err-form').slideDown('slow');
              return false;
          }
  
          var data_string = jQuery('#ajax-form').serialize(); // Collect data from form
          //alert(data_string);
  
          jQuery.ajax({
              type: "POST",
              url: jQuery('#ajax-form').attr('action'),
              data: data_string,
              timeout: 6000,
              error: function(request,error) {
                  if (error == "timeout") {
                      jQuery('#err-timedout').slideDown('slow');
                  }
                  else {
                      jQuery('#err-state').slideDown('slow');
                      jQuery("#err-state").html('An error occurred: ' + error + '');
                  }
              },
              success: function() {
                  jQuery('#ajax-form').slideUp('slow');
                  jQuery('#ajaxsuccess').slideDown('slow');
              }
          });
  
          return false; // stops user browser being directed to the php file
      }); // end click function
  });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>HTML FORM >>>>>>>>>>>>>></p>
  
  <pre><code>&lt;!-- language: lang-html --&gt;
  
  &lt;form name="ajax-form" id="ajax-form" action="mail-it.php" method="post"&gt;
      &lt;p&gt;
        &lt;label for="name"&gt;Name: * 
          &lt;span class="error" id="err-name"&gt;please enter name&lt;/span&gt;
          &lt;br /&gt;
        &lt;/label&gt;
  
        &lt;input name="name" id="name" type="text" /&gt;&lt;br /&gt;&lt;br /&gt;
  
            &lt;label for="phone"&gt;Contact Number: * 
          &lt;span class="error" id="err-phone"&gt;please enter phone number&lt;/span&gt;
          &lt;br /&gt;
        &lt;/label&gt;
  
        &lt;input name="phone" id="phone" type="text" /&gt;
  
        &lt;label for="email"&gt;
          &lt;br /&gt;
          E-Mail: * 
          &lt;span class="error" id="err-email"&gt;please enter e-mail&lt;/span&gt;
          &lt;span class="error" id="err-emailvld"&gt;e-mail is not a valid format&lt;/span&gt;&lt;br /&gt;
        &lt;/label&gt;
        &lt;input name="email" id="email" type="text" /&gt;
        &lt;/p&gt;
  
      &lt;p&gt;
  
  
        &lt;label for="message"&gt;Message:&lt;/label&gt;
        &lt;textarea name="message" id="message"&gt;&lt;/textarea&gt;
  
      &lt;div class="myButton"&gt;&lt;INPUT type="submit" name="" value="" id="send"&gt;&lt;/div&gt;
  
  
  &lt;div class="mainerror"&gt;
  &lt;div class="error" id="err-form"&gt;There was a problem validating the form please check!&lt;/div&gt;
      &lt;div class="error" id="err-timedout"&gt;The connection to the server timed out!&lt;/div&gt;
      &lt;div class="error" id="err-state"&gt;&lt;/div&gt;&lt;/div&gt;
  &lt;/form&gt;
  &lt;div id="ajaxsuccess"&gt;&lt;h2&gt;Successfully sent!!&lt;/h2&gt;&lt;/div&gt;
  </code></pre>
  
  <p>MAIL PHP SEND MAIL-IT.PHP</p>
  
  <pre><code>&lt;!-- language: lang-php --&gt;
  
  &lt;?php
  
  
  
  /* Code by David McKeown - craftedbydavid.com */
  
  /* Editable entries are bellow */
  
  
  
  $send_to = "MYEMAIL@MYDOMAIN.co.uk";
  
  $send_subject = "Website Enquiry ";
  
  
  
  
  
  
  
  /*Be careful when editing below this line */
  
  
  
  $f_name = cleanupentries($_POST["name"]);
  
  $f_phone = cleanupentries($_POST["phone"]);
  
  $f_email = cleanupentries($_POST["email"]);
  
  $f_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: " . $f_name .
  
  "\n\nPhone: " . $f_phone . 
  
  "\n\nE-Mail: " . $f_email . 
  
  "\n\nMessage: \n" . $f_message . 
  
  "\n\n\nTechnical Details:\n" . $from_ip . "\n" . $from_browser;
  
  
  
  $send_subject .= " - {$f_name}";
  
  
  
  $headers = "From: " . $f_email . "\r\n" .
  
      "Reply-To: " . $f_email . "\r\n" .
  
      "X-Mailer: PHP/" . phpversion();
  
  
  
  if (!$f_email) {
  
      echo "no email";
  
      exit;
  
  }else if (!$f_name){
  
      echo "no name";
  
      exit;
  
  }else if (!$f_phone){
  
      echo "no phone";
  
      exit;
  
  }else{
  
      if (filter_var($f_email, FILTER_VALIDATE_EMAIL)) {
  
          mail($send_to, $send_subject, $message, $headers);
  
          echo "true";
  
      }else{
  
          echo "invalid email";
  
          exit;
  
      }
  
  }
  
  
  
  ?&gt;
  </code></pre>
  
  <p>The form does say success, but still not receiving the emails! any ideas?</p>