We have a big list of email addresses in our database from where people have signed up for newsletters for one of our websites.
We have a cron job that uses PHP to grab email address from the database and sends out the newsletters.
When an email gets bounced back, the cron job admin gets an email about it.
If we wanted a script to automatically remove bounced email address from the database, what is the best way to accomplish it? Is there someway to log bounced emails and then have a script parse the log and then remove the bad email addresses? Or is there a way to test for bounced email addresses via PHP?
What you want to do is choose a "universal" bounce email address (say, bounce@example.com). You want to set your header "Return-Path" to "bounce@example.com".
Then, you have an external process check the "bounce@example.com" inbox for messages. Don't use this email account for anything else but bounces.
You will receive bounces, vacation messages, and other types of emails to this inbox. You just need to train your parser to look for certain patterns in the email. Your list of patterns won't be comprehensive at first, but you need to manually look at this inbox from time-to-time so you can further train your parser.
Your parser can be simple and look for simple substrings or even regular expressions. In most cases, regular expressions aren't necessary.
What you need is bounce parser.
You can receive bounce emails over POP3 or IMAP or even read from files (if you can configure your own MTA). Bounce emails will be delivered to email address specified in "Return-Path" header.
There is no good open-source bounce parser for PHP as i known. You can write your own. You can start from discovering parser from mailman (written in python).