the module isn't using the From address which is set in the admin; which is a pretty big deal as most SMTP servers won't authenticate with any from address.

the attach patch has the module use the From variable which is already on the admin form.

Comments’s picture’s picture

liquidcms, the patch will overwrite sender email. This way one will not be able to reply to the Contact module's messages.

jpjanze’s picture

Hi and liquidcms - couldn't this be easily solved by modifying the patch to include a 'replyto' and set the original from address to the 'replyto' address?. I am not a coder, so can't figure it out myself?

And/Or, could you not put the original senders email address in the body somehow "this email is from [sender email] sent via [site name] with links?’s picture

Hi jpjanze,

I'm not familiar with email headers, if in some way it could be possible to set "reply-to" address, that would solve the problem I think.

As for your second point, I think this will require changes in Contact module, and this change might not be appropriate for other users of that module (those who not use SMTP Authentication Support)’s picture

Some explanation on headers:

From this explanation I can conclude that we need to change 'Sender' header. Right now the Sender header is set equivalent to From header. If we set Sender to a parameter from the admin, and leave From as it is now I think we will solve the problem.

I tested, this approach works for me.

rodmaz’s picture

In my tests using this module, the emails only contain the header "Sender:" and no "From:" header.
The module seems to be using the "Sender:" field associated w/ the site and not the field defined by the module.

Simon Georges’s picture

Closing #1147786: "E-mail from address" is not used as a duplicate of this one.

cac2s’s picture

Version:7.x-1.x-dev» 7.x-1.0-beta2

I have a similar situation.

Module is configured to authorize when sending mails (for example, user name is, and some password).

If in the submission form (Webform 7.x-3.18) you specify sender's address as, then sending a content of the form is without error.

But if you specify (in the submission form settings) sender's address, which will be different from, then there is an SMTP server error: 5.7.1 Sender address rejected: not owned by auth user.

P.S.: sorry for my English

Simon Georges’s picture

Version:7.x-1.0-beta2» 7.x-1.x-dev
cac2s’s picture

Version:7.x-1.x-dev» 7.x-1.0-beta2


Simon Georges’s picture

Version:7.x-1.0-beta2» 7.x-1.x-dev
wundo’s picture

Status:Needs review» Closed (works as designed)

A code really similar with the one provided in the patch was already committed a long time ago (lines 73 ~ 100), marking this as work as designed.’s picture

Status:Closed (works as designed)» Needs review

Hi wundo,

My suggestion above was different from the original patch. I suggest to change the Sender header so that no need "to hack to fix reply-to issue". This will also fix "You are not allowed to send mail from domain" error, which still exists.

Here is my patch for the current code in repository. Can you please review it?

diff --git a/smtp.module b/smtp.module
index 4f61170..ea46cb6 100644
--- a/smtp.module
+++ b/smtp.module
@@ -342,7 +342,7 @@ function smtp_drupal_mail_wrapper($message) {

   $mail->From     = $from;
   $mail->FromName = $from_name;
-  $mail->Sender   = $from;
+  $mail->Sender   = variable_get('smtp_from', '');

   // Create the list of 'To:' recipients.’s picture

To make clear bug description.

This module works only when From address is same as SMTP account. This is good when you just send notifications. But Contacts module uses different From address. And most SMTP servers deny to send contact form messages (to prevent spam, as you pretend to be other domain).

So, the module should handle different From address properly. Right now it doesn't.

wundo’s picture

Status:Needs review» Needs work, could you provide a patch file?
Also, when you do it, could you please remove the code that your change will make deprecated?

thanks’s picture


The patch is attached. This fixes "You are not allowed to send mail from domain". I do not touch section with reply-to, I must be was wrong about it.’s picture

new2.03 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
Simon Georges’s picture

Status:Needs work» Needs review
berte’s picture

Version:7.x-1.x-dev» 7.x-1.0

My version: 7.x-1.0
Both patches posted above do not solve the issue. From field in emails is always the username of the smtp authentication (it happens in my case that it's a valid email address).

brunorios1’s picture

Version:7.x-1.0» 7.x-1.x-dev

@berte, please don't change the module version of the issue to the module version you are using.

patches are created to be applied to dev versions, and not to stable versions.

please consider downloading the dev version and testing the patches again.

also, you don't need to "subscribe" manually anymore, on the top right corner you can click "Follow".

thank you.

paulrooney’s picture

Issue summary:View changes

The patch at #17 works. Anonymous and authenticated users are able to send mail by submitting the core contact form. The from address they enter is retained as the sending address.


mvc’s picture

The from address they enter is retained as the sending address.

fwiw this behaviour will change in D8: #111702: Set fixed "from:" and add "Reply-to:" to comply with DMARC

this will help drupal send email to services that implement DKIM/SPF/DMARC anti-spam tests, like yahoo:

Anders Kallin’s picture

I too can confirm that the patch in #17 indeed solves this major problem.

Anders Kallin’s picture

FYI: I just saw that this excellent patch is incompatible with the patch in
My vote is on this patch.

marktompsett’s picture

I would love to use this module as a solution to a DMARC policy issue I am encountering with the Contact form on the site that I am responsible for.
To do that I would need the From header in the message to correctly be the "E-mail from address" that I specify in the "E-mail options" of the "SMTP Authentication Support" screen, which currently it is not.


djinn23’s picture

Not to be that guy, but what expectations would there be to roll this into a stable build or is more testing against this patch required. I have just installed this on my site and seeking as how it is confirmed resolved in the dev build I considered adding that to my sites .... but seeing as how the last Stable release was in Feb I figured it may be rolling out soon. Regardless. Anders brings up an interesting consideration and I am logging this in part to subscribe so I can track the progress.

Thanks for all the efforts.

RunePhilosof’s picture

ericwongcm’s picture

I can also confirm the development version fixed the contact form e-mail from field problem for Drupal 7 described here.

Looks like there is no fix for Drupal 6 yet?

dxx’s picture

No problems, it's good.

alphex’s picture

new408.86 KB
new64.75 KB

Just installed smtp-7.x-1.x-dev via drush.

SMTP email through google apps isn't using the FROM address, it uses the authentication user name in who the message is from when it hits my inbox.

See attached screen shots.

The SMTP user name for authentication is who the email is "FROM", despite there being an address and name provided for "E-mail from address"

SMTP Settings

Test Email Results

Zekvyrin’s picture

Guys can you check this patch:
#2309875-9: Error in 'from' using site-wide contact form and multiple recipients

I think that one has the most expected behaviour.

glynster’s picture

Issue still remains with patch @Zekvyrin suggests. Simply put the from name is working int he SMTP settings but not the email, it always defaults to the SMTP username as @alphex screenshots demonstrate.

bserem’s picture

Status:Needs review» Needs work

Patch on #17 doesn't apply against latest git checkout. I did tha changes manually, but it still doesn't solve the fact that Drupal tries to connect to the SMTP server using the site-wide email (admin/config/system/site-information) instead of the email defined in the SMTP settings.

I'll give it a second try in the night.

andrew.chappell’s picture

I am using 7.x-1.2 and having a similar issue. The email address that is set in /admin/config/system/site-information for site wide usage is overriding the setting used at admin/config/system/smtp. It doesn't matter what I put in to the smtp settings it is always overridden by the site wide setting.

andriyun’s picture

Status:Needs work» Needs review
new2.04 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch doesn_t_use_from_address-1686588-35.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Rerolled patch

Status:Needs review» Needs work

The last submitted patch, 35: doesn_t_use_from_address-1686588-35.patch, failed testing.

andriyun’s picture

Status:Needs work» Needs review
new2.11 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

True rerolled patch :)

andypost’s picture

+++ b/
@@ -100,21 +100,32 @@ class SmtpMailSystem implements MailSystemInterface {
     if ($from == NULL || $from == '') {
+    if ($from == '') {
+    if ($sender == '') {

suppose all should be empty() checks

ehj-52n’s picture

Version:7.x-1.x-dev» 7.x-1.3

I am using the latest release version and still have to adjust the code to get my from used. I applied the following patch:

diff --git a/sites/all/modules/smtp/ b/sites/all/modules/smtp/
index a9314b0..94b140b 100644
--- a/sites/all/modules/smtp/
+++ b/sites/all/modules/smtp/
@@ -88,11 +88,6 @@ class SmtpMailSystem implements MailSystemInterface {

     //Hack to fix reply-to issue.
     $properfrom = variable_get('site_mail', '');
+    // Hack to use smtp_from as from
+    $tmp = variable_get('smtp_from','');
+    if (isset($tmp) && valid_email_address($tmp)) {
+       $properfrom = $tmp;
+    }
     if (!empty($properfrom)) {
       $headers['From'] = $properfrom;
@@ -105,7 +100,6 @@ class SmtpMailSystem implements MailSystemInterface {
       $headers['Reply-To'] = $reply;
+    $from = $properfrom;

     // Blank value will let the e-mail address appear.

Hope this helps.

glynster’s picture

Looks like we are getting very close to a complete resolve @ehj-52n

andypost’s picture

Version:7.x-1.3» 7.x-1.x-dev

This needs to be optimized in next merged reroll
And new release

vprocessor’s picture

Andypost, please, check patch, do you mean something like this?

vprocessor’s picture

Status:Needs work» Needs review

Status:Needs review» Needs work

The last submitted patch, 43: doesn_t_use_from_address-1686588-43.patch, failed testing.

andypost’s picture

Status:Needs work» Needs review

Yep, looks rtbc, just need another pair of eyes

DamienMcKenna’s picture

I tidied up the patch a little and removed the shortened PHP 5.4 array syntax with the PHP 5.2-compatible longer syntax.

Status:Needs review» Needs work

The last submitted patch, 47: smtp-n1686588-47.patch, failed testing.

DamienMcKenna’s picture

Status:Needs work» Needs review

Changing the status back to "needs review" because of a problem with the testbots (see #2645590: Ensure that simpletest job doesn't "fail" testing if no tests are present ).

pinin4fjords’s picture

I used the patch at #47 applied to 7.x-1.3 (doesn't work with current dev). But the test email still uses the site-wide address, and I still get 'Client does not have permissions to send as this sender' when I try to send the test email. Frustratingly this is even the case when I remove all references to 'site_mail' in and hard code an email address. Any idea why?

DamienMcKenna’s picture

I think this would be safe to include in the next release.

gadaniels72’s picture

Tested #47 against 7.x-1.x-dev. Works as expected with the email being sent using the from address in the SMTP configuration and not the site information configuration. Steps taken:

  • Set sitewide email to gdaniels@[mydomain]
  • Set smtp from email to info@[smtp server domain]
  • Sent test email to three email addresses
  • All received as from info@[smtp server domain]
jordanpagewhite’s picture

Status:Needs review» Reviewed & tested by the community

Yep, I can confirm the same as @gadaniels72. "If you receive this message it means your site is capable of using SMTP to send e-mail." I'm going to move this to RTBC unless anyone has an objection.