$.ajax post to PHP mail() using jQuery doesn't work
- by Vian Esterhuizen
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;
?