Skip to main content
  • Guides & Documentation

Knowledgebase

Featured articles, how-to guides and quick tips.

Preventing Drupal 7 From Sending Mail

Sometimes you might wish to stop Drupal from sending any kind of mail. Usually, Drupal will send mail via SMTP, for example, if a user submits a form.

In some situations, such as when using a development environment, you'll want to temporarily stop Drupal from sending any kind of mail.

The code below can quickly be added to your template.php file to stop Drupal from sending email.


function yourtemplatename_mail_alter(&$message) {
  // setting the To value to blank will mean that Drupal has nowhere to send the mail
  $message['to'] = ''; 
}

Just replace 'yourtemplatename' with the machine name of your template, and you're good to go.

Don't forget to remove this code snippet if you require Drupal mail in the future.