Simple tests to differentiate between a permanent and temporary bounce
One of the greatest challenges while writing a bounce processor is to make sure it handles only the right bounces or the permanent ones. A bounce processing script that reacts to every single bounce can lead to mass unsubscription of users from the mailing list and a lot of havoc. Exim helps us here in a great way by including an additional ‘X-Failed-Recipients:’ header to a permanent bounce email. This key can be checked for in the regex function we wrote earlier, and action can be taken only if it exists. /** * Check if the bounce corresponds to a permanent failure * can be added to the extractHeaders() function above */ function isPermanentFailure( $email ) { $lineBreaks = explode( "\n", $email ); foreach ( $lineBreaks as $lineBreak ) { if ( preg_match( "/^X-Failed-Recipients: (.*)/", $lineBreak, $permanentFailMatch ) ) {
$bounceHeaders[ 'x-failed-recipients' ] = $permanentFailMatch;
return true;
}
}
Even today, we have a number of large organisations that send more than 100 emails every minute and still have all bounces directed to / dev/ null. This results in far too many emails being sent to undeliverable addresses and eventually leads to frequent blacklisting of the organisations’ mail server by popular providers like Gmail, Hotmail, etc.
If bounces are directed to an IMAP maildir, the regex functions won't be necessary, as the PHP IMAP library can parse the headers readily for you.