php表单不发送电子邮件

时间:2013-03-01 11:45:34

标签: php forms email

我使用php脚本向指定地址发送电子邮件,但是没有发送电子邮件,即使脚本正在将用户发送到感谢页面。它在一个阶段工作,但随后莫名其妙地停止了。

感谢任何帮助:)

<?php

$to = "emailaddress@gmail.com \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@mydomain.com';//<== 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;
}
}

?> 

2 个答案:

答案 0 :(得分:0)

检查是否收到任何错误。如果邮件发送成功,邮件功能返回true,否则返回false。

答案 1 :(得分:0)

$headers = "From: $email_from \r\n";
  • $email_from尚未定义,也许您在这里遇到错误?
  • 不要忘记启用error_reportingE_ALL以查看所有错误,还检查服务器上的日志以查看问题所在,也许邮件无法通过SMTP服务器发送或等等......
相关问题