You are here

function mail_safety_mail_alter in Mail Safety 7

Same name and namespace in other branches
  1. 8 mail_safety.module \mail_safety_mail_alter()
  2. 7.2 mail_safety.module \mail_safety_mail_alter()

Implements hook_mail_alter().

Filters any e-mail going through the drupal mail system.

If Mail Safety is enabled it stops all mails from being sent depending on the settings it will either send the mails to a default mail address and/or send it to the dashboard.

File

./mail_safety.module, line 110
The core Mail Safety module file

Code

function mail_safety_mail_alter(&$message) {
  if (variable_get('mail_safety_enabled', FALSE)) {
    $message['send'] = FALSE;
  }

  // If mail to dashboard is enabled it'll send the mail to the dashboard.
  if (variable_get('mail_safety_send_mail_to_dashboard', TRUE)) {
    mail_safety_insert_mail($message);
  }

  // If mail to default mail is enabled it will send the mail to the default
  // mail address.
  if (variable_get('mail_safety_send_mail_to_default_mail', TRUE)) {
    $message['to'] = variable_get('mail_safety_default_mail_address', '');
    unset($message['headers']['CC']);
    unset($message['headers']['BCC']);
    $message['send'] = TRUE;
  }
}