0

我正在使用 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;
}
}

?> 
4

2 回答 2

0
$headers = "From: $email_from \r\n";
  • $email_from还没有定义,也许你这里有错误?
  • 不要忘记启用error_reportingE_ALL查看所有错误,还要检查服务器上的日志以查看问题所在,也许邮件无法通过 SMTP 服务器发送或其他...
于 2013-03-01T12:02:09.547 回答
0

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

于 2013-03-01T11:56:29.190 回答