PHP Code

PHP: Pipe Bounce Emails

Another great use for email piping is parsing bounce emails. This is very useful if you have a mailing list and need to remove any invalid or old email addresses. Sending emails to invalid addresses can land you on domain blacklists for possible spamming so it is definitely beneficial to trim any mailing lists you send out to.

Set Up Your Bounce Address

Choose a bounce email address for parsing your bounce emails. I usually choose something like then set up the email address to pipe to a PHP script.

Setting the Return-Path Header

On any emails you want returned to your address you will need to set the Return-Path header on the email. The email header should look like this:


This tells the recipient’s mail server to send any return (bounce) email to the Return-Path address instead of the address in the From header.

Parse the Bounce Email

For this example we’ll take advantage of a Bounce Handler Class to process the bounce email and determine why exactly the email was returned to us.


Pretty straight forward. We read in the email and pass it to the bounce handler. It will tell us if it failed or not. If it fails we can process that address however we deem fit (remove from mailing, etc.). See the file in the Bounce Handler Class to look at the different error types for the email to bounce. Most failed statuses will be the results of an invalid email address.

Continue Reading

  • Chicago Developer

    Do you know how I can determine the source of the pipe?

    I have 3 different email forwarders setup to pipe to a PHP script. Is there a way to determine which of these email ids actually triggered the pipe process?

    • You can try tagging the script with a variable. ie. pipe.php?source=email1.

      Then check against that.

  • evident

    Class is no longer static, it is rewritten in dynamic $this-> notation. please
    rewrite this script.