$.ajax post to PHP mail() using jQuery doesn't work
        Posted  
        
            by Vian Esterhuizen
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Vian Esterhuizen
        
        
        
        Published on 2010-05-17T00:38:56Z
        Indexed on 
            2010/05/17
            0:40 UTC
        
        
        Read the original article
        Hit count: 478
        
Hey,
I looked around on SO and Google, but couldn't really find a solution. Could someone please explain to me why this doesn't work? This is my first time using AJAX to submit a form.
$.ajax({
      type: "POST",
      url: "<?php bloginfo('template_url'); ?>/email.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Contact Form Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
and
<?php
    $name=$_POST['name'];
    $email=$_POST['email'];
    $phone=$_POST['phone'];
    $subject=$_POST['subject'];
    $message=$_POST['message'];
    $quote=$_POST['quote'];
    $to="[email protected]";
    $body="<p>From: ".$name." <".$email."><br />";
    $body.="Phone: ".$phone."<br />";
    $body.="Project: ".$subject."<br />";
    $body.="Quote: ".$quote."</p>";
    $body.="<p>Message:<br /> ".$message."</p>";
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
    $headers .= "From: ".$name."<".$email.">\r\n";
    $headers .= "Reply-To: ".$name."<".$email.">\r\n";
    $subject="New message from FloorShop.ca about \"".$subject."\"";
    @mail($to,$subject,$body,$headers);
    echo $name,$email,$phone,$subject,$message,$quote;
?>
© Stack Overflow or respective owner