点击“提交”按钮后,显示错误:无法发送消息。请提前帮助谢谢。
<?php
$emailTo = "xyz@gmail.com";//change this to the email address which should receive the form data
$redirect_to = 'contact.html'; // Page to show after form is processed
/*
NOTE: do not change anything below this
*/
if( isset($_POST['maximus']) ) {
//honey pot detection
if( $_POST['maximus'] != '' ) {
die('Bad spam bot!!');
}
$message = "";
foreach( $_POST as $field => $val ) {
if( $field != 'maximus' ) {
$message .= $field . " : ". $val . "\n";
}
}
$subject = $_POST['theSubject'];
//send the email
if( mail($emailTo, $subject, $message) ) {
header("Location: $redirect_to");
exit;
} else {
echo "Could not send message.";
}
}
?>
答案 0 :(得分:0)
如果mail()
失败,那么您需要找出原因。您可以检查PHP错误日志,也可以通过调用error_get_last()获取mail(...)
返回的错误消息。
if( mail($emailTo, $subject, $message) ) {
header("Location: $redirect_to");
exit;
} else {
echo "Could not send message.";
print_r(error_get_last());
}
答案 1 :(得分:0)
这是因为电子邮件发送失败了。如果您在localhost中尝试,发送邮件可能会因为没有设置邮件而失败。如果在服务器中,请与您的主机提供商联系。