display error from jquery post
i am posting to a mailer.php file.
mailer.php<?php
if(isset($_POST['submit'])) {
$to = "testabc@gmail.com";
$subject = "Contact via website";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>
here is my js code
$('.submit').click(function(){
$('span.msg').css({'visibility': 'visible'}).text('Sending...');
$.post("mailer.php", $(".contactPage").serialize(),
function(data){
$('span.msg').text('Your Message has been received. Thank you').show();
});
return false;
});
开发者_运维技巧I am getting message of success but email is not received. What i am doing wrong? How to get error detail from mailer.php file and showing in span.msg?
if(mail($to, $subject, $body)){
echo "success";
}else{
echo "fail";
}
JS:
$('.submit').click(function(){
$('span.msg').css({'visibility': 'visible'}).text('Sending...');
$.post("mailer.php", $(".contactPage").serialize(),
function(data){
if(data == 'success'){
$('span.msg').text('Your Message has been received. Thank you').show();
}else{
$('span.msg').text('Your Message has failed. Thank you').show();
}
});
return false;
});
On this page under the Return Values section it says:
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise. It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
So just check if it is returning true or false.
EDIT: Also try checking your spam folder. Perhaps someone on your shared hosting provider is sending spam.
精彩评论