问题
What would be the best way to manage the emails bounces/errors if you are building a web-mass-mailing software ? I plan to use PHP for that.
Before someone start screaming, yes, the lists will be from valid customers who have opt-in.
I know there are desktop software or third party website that can manage such things. I would like to display it with a design similar to the current CMS's visual and be accessible in there.
If the only solution is to connect to a mail server and read the bouncing back messages, then I will head that way. Then, how would you parse the data to flag that email as "invalid"?
Thank you
回答1:
One possible thing you could do aside from having a PHP script read mail from a pop/imap server would be to pipe incoming mail for a certain address to a php script. See Google
You would then read the entire contents of the message in by doing something like $email = file_get_contents('php://stdin');
I've installed the php extension mailparse to assist in parsing RFC emails, but there are other options available. You don't even necessarily have to use anything to parse the message.
Once you have the message, there are a number of indicators you can use to try to flag a message as a bounch. First, see the Wikipedia article about Non Delivery Reports, specifically Format and RFC 6522 - The Multipart/Report Media Type for the Reporting of Mail System Administrative Messages. You can also check for common headers in the message such as X-Failed-Recipients
or Diagnostic-Code
.
Once you've determined a message as a bounce in the PHP mail processor, you can take appropriate action and set a flag in the database related to that email. Mind you, some errors may not mean the address is no good. For example, if a mail server is down for a few days, your MTA may give up, but it doesn't mean the address is no good. Also a user's mailbox could be full.
It wouldn't be a bad idea to log a copy of the bounced message so it could be checked by a person if necessary to diagnose an issue or reverse the flagging or a particular email address.
Here are some additional references:
http://forums.theplanet.com/lofiversion/index.php/t89873.html (note Improvement possibility 2)
https://stackoverflow.com/questions/5700034/how-do-i-process-a-bounce-email-to-find-the-error-code
Bounce Email handling with PHP?
Hope that helps.
来源:https://stackoverflow.com/questions/9137370/how-to-manage-emails-bouncing-and-errors-in-php