PHP mail function works sometimes

可紊 提交于 2019-12-01 08:35:26

问题


I am writing a script that needs to send an e-mail through the PHP mail function. As it is written below, it works when sending an e-mail to a gmail account, but not an account on my domain. We are running an Exchange server. As of now, the e-mails are sent from _www@server. Does anyone know of an issue with php mail and Exchange (or maybe even e-mail addresses beginning with an underscore and Exchange??)? Or perhaps there is another issue here? The mail function will return true no matter what.

Thank you,

Jeff

$user = $_POST['email'];

$to = "someone@domain.org";

$subject = "Request to Reset EduTube Password";

$body = "Thank you " . $_POST['email'] . " for using the EduTube Password Reset System.\n\n";
$body .= "Please click the following link, or copy & paste it into your browser to reset your password.\n\n";
$body .= "http://testing.domain.org/reset.php?user=" . $user;

$headers = "From: someone@domain.org";

$from = "EduTube Password Reset System";

if (mail($to, $subject, $body, $headers)){

echo "Your email has been sent.  Please check your inbox shortly.";
echo "<br/><a href='http://testing.domain.org'>Click</a>";

}

回答1:


mail()'s delivery function ends when it hands off your mail to the SMTP server. Its sole responsibility is the real-world equivalent of taking your envelope and dropping it into the mailbox on the corner. The rest of the postal service (emptying that box, running it through processing centers, flying it to the recipient's country/city, etc...) is completely outside of mail()'s scope. As long as the envelope drops into the mailbox, mail() will return true and pretend it was delivered.

So... check your SMTP server's logs to see what really happened to the mail. Maybe it got marked as spam by the receiver and bounced. Maybe it's stuck in a queue somewhere, etc... Only the logs will tell you this - anything you can see/do in PHP is useless, because PHP and mail() only do maybe 1% of the email sending/delivery process, and something's wrong in that other 99%.



来源:https://stackoverflow.com/questions/6666791/php-mail-function-works-sometimes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!