php表单不发送电子邮件
问题描述:
我正在使用php脚本向给定地址发送电子邮件,但是没有发送电子邮件,即使脚本正在将用户发送到感谢页面。它在一个阶段工作,但然后莫名其妙地停下来。php表单不发送电子邮件
任何帮助表示赞赏:)
<?php
$to = "[email protected] \r\n";//<== update the email address
$headers = "From: $email_from \r\n";
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = '[email protected]';//<== update the email address
$email_subject = "Contact via the website";
$email_body = "You have received a new message from $name.\n\n".
"Here is the message:\n $message\n\n\n".
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: http://domain.com/thank-you/');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
答
检查,如果你得到任何和error.The邮件功能如果邮件成功发送,如果它不列入返回false返回true。
答
$headers = "From: $email_from \r\n";
-
$email_from
还没有确定,也许你有错误吗? - 不要忘记启用
error_reporting
到E_ALL
看到所有的错误,还要检查服务器日志,看看那里的问题,也许邮件无法通过SMTP服务器或东西...被发送
那么,什么是错误? – 2013-03-01 11:46:10
http://www.php.net/manual/en/function.mail.php#101588 – bcmcfc 2013-03-01 11:47:51
即使该脚本正在将用户发送给“谢谢”页面,因为您没有检查发送的邮件或不。你只是简单地使用'header()'函数。 'mail'函数返回bool与'if'语句一起使用并检查。 – Vinay 2013-03-01 11:49:15