Prevent Spamming During Drupal Debugging and Testing
Set up the Drupal reroute_email module on your Pantheon Drupal site.
If your Drupal site sends outbound emails, you don't want to accidentally spam your users or customers from your Dev or Test environments. Maybe your site has a complex editorial workflow that alerts people when action is required, or maybe you’re redesigning email templates for your drip marketing campaign. Whatever your use case, you’ll want to make sure that you’re not accidentally spamming customers during debugging or quality assurance testing, and you’ll want to add the Reroute Email module to your developer toolkit.
If you don't manually change the settings stored in the database, you are at risk of accidentally spamming users during debugging or quality assurance testing.
Reroute Email is easy to setup and the settings persist, even when moving the database between environments. You can install the reroute email and enable it in all environments, and configure it via the settings.php with environmental variables to ensure you don't spam users during debugging or testing.
You’ll be able to funnel all development and testing emails to a single inbox and will not have to log in to several email accounts to test your business expectations.
Installation
You can use SFTP on Pantheon or the Drupal UI to install a module. Alternatively, you can use Git to keep automated backups running on Dev.
For instance, you can use a start state and perform a git clone of the Pantheon site.
Add a contrib directory to help keep modules organized. You can use Drush to download contrib modules into the directory.
The following line isn’t necessary, but it’s a good idea to use git status to understand the state of your local Git repository, especially if you’re new to Git. If you’re just starting with Git, execute git status after each step.
Use the following command to add the module to Git:
Commit and push the module to Pantheon.
Now, check your Site Dashboard and you’ll see that the module’s code has been deployed to your Dev environment.
Configuration
If you don’t have a settings.php file, copy the default.settings.php file. You can use the following command to copy:
Using your favorite editor or IDE, open the settings.php, and add the following code for Drupal:
In order for the snippet to work as intended, the module must be enabled in all environments. The PANTHEON_ENVIRONMENT variable changes the reroute email settings based on environment. The configuration in settings.php overrides any settings in the Drupal Admin UI. If your site isn't on Pantheon, look for available Superglobals to aid in your configuration.
Stage and Commit settings.php
In order for the settings.php configuration to work correctly, the reroute_email module must be enabled in all environments.
Next, push the code to Pantheon.
Push the code to Test and Live and enable the module in all environments. You can do this through the Site Dashboard and the Drupal Admin UI, or by using Terminus and Drush:
Now the Dev environment’s settings page for the reroute_email module (/admin/config/development/reroute_email) should display a checked box for Email Rerouting and Show rerouting description in mail body, as well as the destination email addresses.
If you don’t see what you’re expecting, review your settings.php and ensure the commit is displayed on your Dashboard:
Go Forth and Test
Now, when Drupal sends out an email from any environment (except Live), it will get rerouted to the email address specified in the settings.php file. The settings.php will ensure emails are not rerouted on Live. Make sure you’re using a SMTP gateway on Live to ensure email deliverability.

