From 93c8d34dbcf5b8138518ad98b14c622d58c301b8 Mon Sep 17 00:00:00 2001 From: naxoc Date: Wed, 30 May 2012 11:27:45 -0400 Subject: [PATCH] Issue #209672 by dshaw, theborg, cburschka, Rob Loach, carlos8f, gdud, pillarsdotnet, olamaekle, naxoc: Use site name in From: header for system e-mails. --- core/includes/mail.inc | 5 +++-- core/modules/system/tests/mail.test | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/core/includes/mail.inc b/core/includes/mail.inc index f58a76e799b7421e382c766a730b071524435437..544ce39e12f09122dd33e35b8437338154a3e855 100644 --- a/core/includes/mail.inc +++ b/core/includes/mail.inc @@ -145,9 +145,10 @@ function drupal_mail($module, $key, $to, $language, $params = array(), $from = N // To prevent e-mail from looking like spam, the addresses in the Sender and // Return-Path headers should have a domain authorized to use the originating // SMTP server. - $headers['From'] = $headers['Sender'] = $headers['Return-Path'] = $default_from; + $headers['Sender'] = $headers['Return-Path'] = $default_from; + $headers['From'] = variable_get('site_name', 'Drupal') . ' <' . $default_from . '>'; } - if ($from) { + if ($from && $from != $default_from) { $headers['From'] = $from; } $message['headers'] = $headers; diff --git a/core/modules/system/tests/mail.test b/core/modules/system/tests/mail.test index 38c6dc8c0af2d94d654a8daff89f80ba2505d661..37fb6cf496c4e2064cdd2eeee658d3162487f6e2 100644 --- a/core/modules/system/tests/mail.test +++ b/core/modules/system/tests/mail.test @@ -67,6 +67,28 @@ class MailTestCase extends WebTestBase implements MailInterface { } /** + * Checks for the site name in an auto-generated From: header. + */ + function testFromHeader() { + global $language; + $default_from = variable_get('site_mail', ini_get('sendmail_from')); + $site_name = variable_get('site_name', 'Drupal'); + + // Reset the class variable holding a copy of the last sent message. + self::$sent_message = NULL; + // Send an e-mail with a sender address specified. + $from_email = 'someone_else@example.com'; + $message = drupal_mail('simpletest', 'from_test', 'from_test@example.com', $language, array(), $from_email); + // Test that the from e-mail is just the e-mail and not the site name and + // default sender e-mail. + $this->assertEqual($from_email, self::$sent_message['headers']['From']); + + self::$sent_message = NULL; + // Send an e-mail and check that the From-header contains the site name. + $message = drupal_mail('simpletest', 'from_test', 'from_test@example.com', $language); + $this->assertEqual($site_name . ' <' . $default_from . '>', self::$sent_message['headers']['From']); + } + /** * Concatenate and wrap the e-mail body for plain-text mails. * * @see Drupal\Core\Mail\PhpMail -- 1.7.10.819.g661bfd5.dirty