Today a customer called me and asked why it is, that in their MS Outlook mails from their (drupal) website are marked as something like "this mail is sent to foo@customer.com IN BEHALF OF bar@customer.com".
After some investigations I figured out that in the mail headers the recipient is written nicely by webform (like To: foo@customer.com
). But there is also a field Sender: bar@customer.com
with the main website e-mail address (the one from /admin/settings/site-information), what is causing the confusion at my customers staff.
Maybe it's cool to have this Sender hader-information in webform mails. But is there a way to switch it off on this website of my customer?
I have not read through the sourcecode of webform yet. Maybe there is some obvious explanation for this header-field....
...do you know?
Comments
Comment #1
quicksketchUsing the site e-mail address is the default when new webforms are created. You just need to edit the webform node, change the sender e-mail address to "Custom" and enter a different e-mail address you'd like the e-mails to be sent from.
Comment #2
guedressel CreditAttribution: guedressel commentedI'm not talking about the Sender-field in the edit-form. I'm talking about the "Sender: " header in the mail text.
Here is a mail header from a generated mail:
visitor@domain.com is the address the visitor entered in the webform
foo@customer.com is the recipient address entered in the edit-form of the webform
bar@customer.com is the site-mail entered in the site-information form
Comment #3
TrickerTreater CreditAttribution: TrickerTreater commentedI've had the same problem. I always found Outlook & Entourage to be the culprits. I'd love to know the solution.
Comment #4
quicksketchIt looks like Drupal core is responsible for these headers, I know that Webform isn't adding them. In includes/mail.inc around line 104, there's this bit of code:
So basically, it's going to be forced onto any e-mails sent by Webform. The spam argument is valid though, since Drupal is sending the e-mail from it's server, giving e-mails a different Sender could cause e-mails to be marked as spam on the receiving end.
If you really want to get rid of these headers, you can implement hook_mail_alter() in a custom module and remove the headers from all e-mails that Drupal sends out:
Comment #5
jwinton CreditAttribution: jwinton commentedJust wanted to note that I was having this problem in Lotus Notes and the custom module solution worked great. Thanks, quicksketch!
Comment #6
quicksketchComment #7
Marko B CreditAttribution: Marko B commentedI see this is still the case with drupal 7 and webform and other mail sending modules. Is there some other way to fix this. No module or thinking in drupal core dev team this isn't way to do this (limit this)?
Maybe using http://drupal.org/project/smtp can help on this, haven't tried it yet.
Also, will try your custom module, but wondering is this the right way? unseting something that is usually in emails could also make it ready to be spam flaged?
Comment #8
Marko B CreditAttribution: Marko B commentedhttp://drupal.org/node/656472
here is some discussion and here http://drupal.stackexchange.com/questions/7311/set-drupal-7-from-email-a...
Comment #9
Marko B CreditAttribution: Marko B commentedAnd here is a module that should help on this issue http://drupal.org/project/mail_headers
Comment #10
puddyglumThanks quicksketch for your snippet above. In order to prevent this problem completely, we had to get rid of the return path as well
Comment #11
jo_as_neo CreditAttribution: jo_as_neo commentedIn our project, the problem with IN BEHALF was resolved with :
Unsetting "Sender" as well meant that we lost the Reply-to information we provided (we wanted to put the email of the user who submitted the form, there).
Comment #12
mmarinescu CreditAttribution: mmarinescu commentedHello all,
Could you please advise where do you write that code?
Thanks
Comment #13
puddyglum@mmarinescu You place that code in a custom module created just your site's hooks. If you do not have a custom module, you need to create one. See https://www.drupal.org/node/1074362
Comment #14
weseze CreditAttribution: weseze commentedI used this snippet of code to force the same email address for all headers:
Comment #15
wesleymusgrove CreditAttribution: wesleymusgrove commented@weseze, I just want to share my experience based on your helpful snippet. At least with what I'm seeing in Drupal 8.2.4 and Webform 8.x-5.0-beta4, the
$message['headers']['Reply-To']
was actually supposed to have a lowercase "t" like$message['headers']['Reply-to']
. That simple change had me scratching my head for a good day and a half :/.However I am still unable to hit a breakpoint in my own custom
hook_mail_alter()
implementation.In Line 267 of docroot/core/lib/Drupal/Core/Mail/MailManager.php, this
alter
function says it's going to allow all modules to alter the resulting email.Therefore this correctly falls into
webform_mail_alter(&$message)
on line 238 of docroot/modules/webform/webform.module, but not in my custom implementation ofMYTHEME_mail_alter(&$message)
, which I have in the active and default theme'sdocroot/sites/all/themes/MYTHEME/MYTHEME.theme
. I have cleared all my caches after defining the new hook.Is it not hitting my custom implementation of
hook_mail_alter()
because it's in my theme file instead of in a custom module?Comment #16
wesleymusgrove CreditAttribution: wesleymusgrove commentedFollowing up to say that putting my custom implementation of hook_mail_alter in a custom module instead of in the custom theme file worked.
Comment #17
usmanjutt84comment #4 works for me
Comment #18
bikrampal CreditAttribution: bikrampal commentedHi, This is coming automatically based on the email ID used in your website. If your sender email is different from the Site information email then you will get this message like site-email@example.com on behalf of sender-email@example.com.
BUT you can alter email through web hook:
function yourmodule_mail_alter(&$message) {
if (isset($message['headers']['Reply-To'])) {
$message['headers']['From'] = $message['headers']['Reply-To'];
$message['headers']['Sender'] = $message['headers']['Reply-To'];
$message['headers']['Errors-To'] = $message['headers']['Reply-To'];
$message['headers']['Return-Path'] = $message['headers']['Reply-To'];
}
}