View source
<?php
define('REROUTE_EMAIL_ADDRESS', 'reroute_email_address');
function reroute_email_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/reroute_email',
'title' => 'Reroute Email',
'description' => 'Reroute emails to a test address.',
'callback' => 'drupal_get_form',
'callback arguments' => array(
'reroute_email_settings',
),
'type' => MENU_NORMAL_ITEM,
);
}
return $items;
}
function reroute_email_settings() {
$form[REROUTE_EMAIL_ADDRESS] = array(
'#type' => 'textfield',
'#title' => t('Email address'),
'#required' => TRUE,
'#default_value' => variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from')),
'#size' => 35,
'#description' => t('The email address to reroute all emails from the site to.'),
);
return system_settings_form($form);
}
function reroute_email_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers) {
global $base_url;
unset($headers['Bcc']);
unset($headers['Cc']);
$msg = "This email was rerouted.\n";
$msg .= "Web site: @site\n";
$msg .= "Mail key: @key\n";
$msg .= "Originally to: <@to>\n";
$msg .= "-----------------------\n";
$body = t($msg, array(
'@site' => $base_url,
'@to' => $to,
'@key' => $mailkey,
)) . $body;
$to = variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from'));
}