Problem/Motivation
I have code to manually send various emails from our site. We set different From addresses in the mail header depending on the email we send. We have been using Mimemail (and for test, also php mail) senders for sending email and this has always worked fine. We recently had to switch to using SMTP for sending email and just noticed that we are no longer able to set the From address as SMTP (when the smpt config From is not set) always uses the site email address (as opposed to checking first if it is already set).
Steps to reproduce
Proposed resolution
SMTP should not set the From address if it is already set. Possibly if the SMTP From is set then it makes sense; but if it isn't set, it shouldnt be automatically setting it to the site email.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | smtp from.jpeg | 72.84 KB | pablonicolas |
Comments
Comment #2
undersound3 commentedPossible duplicate of https://www.drupal.org/project/smtp/issues/3462824
Comment #3
pablonicolasIt seems to be working fine on my tests. If I set an email address on the Config Form, it overriddes the Email address from the site settings.
I think using
hook_mail_alteris the way to go if you want to change the "From" value depending the email.Comment #4
liquidcms commentedI think you missed the point of this issue. Yes, setting From on SMTP config form, sets From. Not setting From uses Site address. Using mail_alter to set From, is overwritten depending on which of those set on SMTP config form.
In other words, setting nothing for From on SMTP config form should not override s earlier set From address.
Comment #5
liquidcms commentedI found the trick. The SMTP module looks for specific message values from_mail and from_name. If those are set, then it uses those to build the From address. This code in a mail alter does the trick: