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>";
}
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