sptrsn Posted January 17, 2012 Share Posted January 17, 2012 We're running a foreclosure bid service that sends a lot of email status notifications. (ie bid received, high number, outbid, sale results etc) Most days it works great. However, occasionally, there are a handful of emails that people claim they never got. I have a log file I write to immediately after the mail function. It is not conditioned on the return var... it just writes the mail vars to the log. So according to the log it APPEARS that all the emails were sent. I've asked the host to check if there are any smtp errors. He says he doesn't see any. So..... is there a best practice for attempting to send again on failure? Should I just try a few times if it returns false? Should I write it all to the db, use a pending/success flag and cron to work through the pendings? That way it continues to attempt failures and I can run a failure report. I don't know. Any bright ideas? Quote Link to comment https://forums.phpfreaks.com/topic/255249-periodic-mail-fail-ideas-for-failure-looping/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 17, 2012 Share Posted January 17, 2012 Once you add the mail function returned status to the logged information, you will be able to determine if you can do anything on the php/sending side. The php mail function only returns the status that the sending mail server passes back to it at the time the email is given to your sending mail server. That's the end of php's involvement in the process. The status basically means that your sending mail server accepted the email from your php script. It does not mean that the mail server will even attempt to send it or that it was actually sent or that it was successfully received. About the only thing that comes to mind that you can do is to put a valid email address into the Return-path: mail header and then check that mail box for messages sent back from the receiving mail servers. Quote Link to comment https://forums.phpfreaks.com/topic/255249-periodic-mail-fail-ideas-for-failure-looping/#findComment-1308690 Share on other sites More sharing options...
sptrsn Posted January 17, 2012 Author Share Posted January 17, 2012 Thanks for the input. I like the idea of the return-path. Hadn't considered that it might return delivery failure errors. So... I'm going to add a return-path header. Grab the return var and make three attempts on error with a small sleep() in between. (anything wrong with this?) Write the failed mail vars to a log file and/or mail the errors to me so at least I can run interference on failure. In theory, doing this... I would know if the mail function failed to pass the vars to smtp and be able to distinguish that from a delivery failure. Am I correct in my assumptions? Quote Link to comment https://forums.phpfreaks.com/topic/255249-periodic-mail-fail-ideas-for-failure-looping/#findComment-1308696 Share on other sites More sharing options...
PFMaBiSmAd Posted January 17, 2012 Share Posted January 17, 2012 If calling mail() fails, repeatedly doing it will likely also fail. Typical error messages are - invalid/missing/malformed address, authentication required/relaying attempt, no sending mail server (it's down or off), blacklisted addresses/domains,... If you have php's error_reporting set to E_ALL and log_errors set to ON, any returned error message will get logged to the error log file. You can also use error_get_last (php5.2 or higher) or $php_errormsg (if you set track_errors first) to get any error message that is produced when the mail() call fails. Quote Link to comment https://forums.phpfreaks.com/topic/255249-periodic-mail-fail-ideas-for-failure-looping/#findComment-1308697 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.