[英]PHP mail isn't sending - headers set incorrectly?
之前,我已经使用PHP的mail()函数成功发送了邮件,对于密码重置通知电子邮件,我复制了在其他地方使用的语法,但是我想我搞砸了它,因为它没有到达目的地。 这是我正在使用的代码:
$headers = 'To:'.$email."\r\n";
$headers .= 'From: webmaster@aromaclear.co.uk'."\r\n";
$to = $email."\r\n";
$subject = 'AromaClear Password Reset Notification'. "\r\n";
$msg = 'From: AromaClear'."\r\n";
$msg .='Subject: Your New Password'. "\r\n";
$msg .= 'Message: Your new password is '.$newpass."\r\n";
$msg.= 'If you have received this e-mail in error, please ignore it.'. "\r\n";
mail($to, $subject, $msg, $headers);
有什么想法吗?
尝试查看服务器的邮件日志,以了解为什么它不被转发。 例如,可能是该服务器的sendmail想要-F标志作为From头,而不是在头文本中指定它。
mail($to, $subject, $msg, $headers, "-f $from");
另外,您似乎在做很多额外的/怪异的工作。 这要容易得多:
$subject = "AromaClear Password Reset Notification";
$headers = "From: webmaster@aromaclear.co.uk";
$msg = "Your new password is $newpass\r\nIf you have received this e-mail in error, please ignore it.\r\n.";
if(mail($email, $subject, $msg, $headers))
{
//handle success
}
else
{
//handle failure
}
根据您的喜好更改样式。
您检查过mail()的返回值了吗? 如果不是FALSE,则表示可以接受,并且代码还可以,但是其他地方有些混乱。
对我来说很好,也许
if (mail($to_email,$subject,$message, $headers))
echo 'Success';
else
echo 'Error';
}
这可能会让您知道它是否正在尝试发送。
只是不要在各处添加“ \\ r \\ n”,仅将其用于分隔标题。 在消息中,您只能使用\\ n,它将起作用。 并且在主题和接收者的末尾,不需要“ \\ r \\ n”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.