diff --git a/smtp.mail.inc b/smtp.mail.inc
index 6e35099..42cc421 100644
--- a/smtp.mail.inc
+++ b/smtp.mail.inc
@@ -100,21 +100,32 @@ class SmtpMailSystem implements MailSystemInterface {
       $headers['Reply-To'] = $reply;
     }
 
-    // Blank value will let the e-mail address appear.
 
+    // Use sender to prevent 'You are not allowed to send mail from domain $from'
+    if (($sender = variable_get('smtp_from', '')) == '') {
+      // If smtp_from config option is blank, use site_email.
+      $sender = variable_get('site_mail', '');
+    }
+
+    // Blank value will let the e-mail address appear.
+    // If from e-mail address is blank, use smtp_from config option.
     if ($from == NULL || $from == '') {
-      // If from e-mail address is blank, use smtp_from config option.
-      if (($from = variable_get('smtp_from', '')) == '') {
-        // If smtp_from config option is blank, use site_email.
-        if (($from = variable_get('site_mail', '')) == '') {
-          drupal_set_message(t('There is no submitted from address.'), 'error');
-          if ($logging) {
-            watchdog('smtp', 'There is no submitted from address.', array(), WATCHDOG_ERROR);
-          }
-          return FALSE;
-        }
+      $from = $sender;
+    }
+
+    if ($from == '') {
+      drupal_set_message(t('There is no submitted from address.'), 'error');
+      if ($logging) {
+        watchdog('smtp', 'There is no submitted from address.', array(), WATCHDOG_ERROR);
       }
+      return FALSE;
     }
+
+    if ($sender == '') {
+       // Will work only for servers that do not check for phishing.
+       $sender = $from;
+    }
+
     if (preg_match('/^"?.*"?\s*<.*>$/', $from)) {
       // . == Matches any single character except line break characters \r and \n.
       // * == Repeats the previous item zero or more times.
@@ -132,7 +143,7 @@ class SmtpMailSystem implements MailSystemInterface {
     // Defines the From value to what we expect.
     $mailer->From     = $from;
     $mailer->FromName = $from_name;
-    $mailer->Sender   = $from;
+    $mailer->Sender   = $sender;
 
 
     // Create the list of 'To:' recipients.
