diff --git a/smtp.mail.inc b/smtp.mail.inc index a053187..9ada4dd 100644 --- a/smtp.mail.inc +++ b/smtp.mail.inc @@ -85,19 +85,29 @@ 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'); - 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'); + watchdog('smtp', 'There is no submitted from address.', array(), WATCHDOG_ERROR); + return FALSE; + } + + if ($sender == '') { + $sender = $from; // will work only for servers that do not check for phishing + } + if (preg_match('/^"?.*"?\s*<.*>$/', $from)) { // . == Matches any single character except line break characters \r and \n. // * == Repeats the previous item zero or more times. @@ -113,7 +123,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.