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