This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
oliverdavies.uk-old-sculpin/source/_posts/configuring-the-reroute-email-module.md
Oliver Davies 85a10c545b Run prettier on all *.md files
```
prettier '{app,source}/**/**.md' --write
```
2020-03-08 17:57:45 +00:00

2.3 KiB

title date excerpt tags draft
Configuring the Reroute Email Module 2014-12-22 How to configure the Reroute Email module, to prevent sending emails to real users from your pre-production sites!
drupal
drupal-6
drupal-7
drupal-planet
email
true

Reroute Email module uses hook_mail_alter() to prevent emails from being sent to users from non-production sites. It allows you to enter one or more email addresses that will receive the emails instead of delivering them to the original user.

This is useful in case where you do not want email sent from a Drupal site to reach the users. For example, if you copy a live site to a test site for the purpose of development, and you do not want any email sent to real users of the original site. Or you want to check the emails sent for uniform formatting, footers, ...etc.

As we don't need the module configured on production (we don't need to reroute any emails there), it's best to do this in code using settings.local.php (if you have one) or the standard settings.php file.

The first thing that we need to do is to enable rerouting. Without doing this, nothing will happen.

$conf['reroute_email_enable'] = TRUE;

The next option is to whether to show rerouting description in mail body. I usually have this enabled. Set this to TRUE or FALSE depending on your preference.

$conf['reroute_email_enable_message'] = TRUE;

The last setting is the email address to use. If you're entering a single address, you can add it as a simple string.

$conf['reroute_email_address'] = 'person1@example.com';

In this example, all emails from the site will be rerouted to person1@example.com.

If you want to add multiple addresses, these should be added in a semicolon-delimited list. Whilst you could add these also as a string, I prefer to use an array of addresses and the implode() function.

$conf['reroute_email_address'] = implode(';', array(
  'person1@example.com',
  'person2@example.com',
  'person3@example.com',
));

In this example, person2@example.com and person3@example.com would receive their emails from the site as normal. Any emails to addresses not in the array would continue to be redirected to person1@example.com.