How to set up email bounce handling using SilverStripe and cPanel

How to set up email bounce handling using SilverStripe and cPanel
By Jeremy on December 1, 2009.

These are instructions for setting up bounce handling for SilverStripe, and assumes you use cPanel for site managment. You should be able to mirror these steps accross to other systems also.

Here is the SilverStripe documentation on the silverstripe bounce handling:

  • Download this file: BounceEmailTask.php , and store it in your SilverStripe /mysite/code/ directory. This class handles incoming emails, and determines if they are bounces, and then records the bounce accordingly. Sam Minnee from SilverStripe provided the original code, and I converted it into a SS ScheduledTask (even though its not a cron job task). More about ScheduledTasks here. 
  • Set up a email address
  • Set up a cPanel filter that pipes emails that are "To:" to a program:

    "| php -q /home/yourusername/public_html/sapphire/cli-script.php /BounceEmailTask"

    (Everything before  /sapphire/cli-script.php may differ on your hosting)
    I also set another rule for the bounces to be delivered to the inbox, just incase they are needed.
  • Make sure you have your site path set in your _ss_environment.php:

    global $_FILE_TO_URL_MAPPING;
    $_FILE_TO_URL_MAPPING['/home/yourusername/public_html'] = '';

Again the site path could differ on your server.

Test by sending a newsletter, or email to an address that is very likely to bounce, eg:


Feel free to modify the BounceEmailTask class to suit your needs.

Let me know of any problems or issues you have setting this up.