mailer.phpPHP发送电子邮件
<?php
if(isset($_POST['submit'])) {
$to = "[email protected]";
$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 "1";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "0";
}
?>
jQuery代码
$('.submit').click(function(){
$('span.msg').css({'visibility': 'visible'}).text('Sending...');
$.post("mailer.php", $(".contactPage").serialize(),
function(data){
$('span.msg').text((data == "1") ? 'Your Message has been received. Thank you' : "Could not send your message at this time").show();
});
return false;
});
我总是得到
Could not send your message at this time
我在PHP几乎没有知识,什么我做错了吗?
该怎么做? – coure2011 2010-08-29 20:03:47
我建议您打印{成功:true}而不是1或0。 在Jquery中使用一个JSON库或简单地使用(虽然不推荐) function(data){response = eval(data); if(response.success){alert(“Msg sent”); }} – 2010-08-29 20:26:55
任何代码片段? – coure2011 2010-08-29 22:32:25