You are here

function reroute_email_mail_alter in Reroute Email 5

Same name and namespace in other branches
  1. 8 reroute_email.module \reroute_email_mail_alter()
  2. 6 reroute_email.module \reroute_email_mail_alter()
  3. 7 reroute_email.module \reroute_email_mail_alter()
  4. 2.x reroute_email.module \reroute_email_mail_alter()

Implements hook_mail_alter().

This hook is required to change the destination of outgoing emails.

File

./reroute_email.module, line 51
Reroute Email module

Code

function reroute_email_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers) {
  global $base_url;

  // Unset Bcc and Cc fields to prevent emails from going to those addresses.
  unset($headers['Bcc']);
  unset($headers['Cc']);

  // Format a message to show at the top.
  $msg = "This email was rerouted.\n";
  $msg .= "Web site: @site\n";
  $msg .= "Mail key: @key\n";
  $msg .= "Originally to: <@to>\n";
  $msg .= "-----------------------\n";

  // Prepend to the body of the email.
  $body = t($msg, array(
    '@site' => $base_url,
    '@to' => $to,
    '@key' => $mailkey,
  )) . $body;

  // Change the $to address to be the one we defined.
  $to = variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from'));
}