If the Sender header is passed in the headers params it is overwritten by the mimemail_headers function. Perhaps there is a reason not to, but I think it makes sense to change the line
$headers = array_merge($headers, array('From' => $from, 'Sender' => $from, 'Return-Path' => "<$from_email>"));
to
$headers = array_merge(array('From' => $from, 'Sender' => $from, 'Return-Path' => "<$from_email>"), $headers);
That way From, Sender, and Return-Path are not overwritten to defaults if they already exist in the headers.
Comments
Comment #1
sgabe commentedThe mimemail_headers() function allows to overwrite the standard headers when its called with the $from parameter. I think this works as designed. Have you encounter any problem with this?
Comment #2
sean_fremouw commentedYes, I needed separate Sender and From headers. When sending a message via drupal_mail I believe the correct option to set the Sender header in hook_mail is a line like:
which then ends up in the $headers variable in mimemail_headers(). So then that array_merge line overwrites Sender with what is in $from. Switching the merge order prevented the overwrite.
Comment #3
sgabe commentedPatch committed to both branches.
Comment #4
sgabe commentedUnfortunately it seems I need to revert this because it breaks the headers when the sender is specified for the messages. We need a better solution for this.
Comment #5
sgabe commentedThe problem here is that the purpose of mimemail_headers() is to provide default values when the message sent directly via a mimemail() call, but since we use drupal_mail() to prepare and alter the message these headers are already existing and we need to overwrite them...
Comment #6
sgabe commentedThe attached patch seems to work for me. Please test it and report back.
Comment #7
sgabe commentedCommitted to both branches.
Comment #9
sdague commentedI just ran into an issue caused by this patch. With this patch in place, specifying sender in the mimemail() call directly is now completely ignored, just spent the last couple hours debugging that it was this changeset that did it.
If that's no longer a supported way to call into mimemail directly, what would the right way to do it be?
Comment #10
sgabe commented@sdague: See #2.
Comment #11
sgabe commented