Modifying the $from variable in hook_mail_alter does not change the from address
jsenich - June 26, 2007 - 20:23
| Project: | Drupal |
| Version: | 5.x-dev |
| Component: | base system |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | won't fix |
Jump to:
Description
The problem is that the value for $from in drupal_mail is merged into the $headers variable, along with some other defaults, before the code for hook_mail_alter runs:
// To prevent e-mail from looking like spam, the addresses in the Sender and
// Return-Path headers should have a domain authorized to use the originating
// SMTP server. Errors-To is redundant, but shouldn't hurt.
$default_from = variable_get('site_mail', ini_get('sendmail_from'));
if ($default_from) {
$defaults['From'] = $defaults['Reply-To'] = $defaults['Sender'] = $defaults['Return-Path'] = $defaults['Errors-To'] = $default_from;
}
if ($from) {
$defaults['From'] = $defaults['Reply-To'] = $from;
}
$headers = array_merge($defaults, $headers);
// Custom hook traversal to allow pass by reference
foreach (module_implements('mail_alter') AS $module) {
$function = $module .'_mail_alter';
$function($mailkey, $to, $subject, $body, $from, $headers);
}I think that the $headers variable should be merged with the from defaults after the code for hook_mail_alter is run:
// Custom hook traversal to allow pass by reference
foreach (module_implements('mail_alter') AS $module) {
$function = $module .'_mail_alter';
$function($mailkey, $to, $subject, $body, $from, $headers);
}
// To prevent e-mail from looking like spam, the addresses in the Sender and
// Return-Path headers should have a domain authorized to use the originating
// SMTP server. Errors-To is redundant, but shouldn't hurt.
$default_from = variable_get('site_mail', ini_get('sendmail_from'));
if ($default_from) {
$defaults['From'] = $defaults['Reply-To'] = $defaults['Sender'] = $defaults['Return-Path'] = $defaults['Errors-To'] = $default_from;
}
if ($from) {
$defaults['From'] = $defaults['Reply-To'] = $from;
}
$headers = array_merge($defaults, $headers);| Attachment | Size |
|---|---|
| common.inc__3.patch | 1.38 KB |

#1
The desired functionality is to let implementations of hook_mail_alter() to have free reign over the outgoing email. Merging headers afterwards would make it impossible to alter some headers.