Commit 33e284e8 authored by catch's avatar catch

Issue #209672 by pillarsdotnet, theborg, penyaskito, cburschka, naxoc, Rob...

Issue #209672 by pillarsdotnet, theborg, penyaskito, cburschka, naxoc, Rob Loach, carlos8f, gdud, olamaekle: Added Use site name in From: header for system e-mails.
parent 72b297ff
...@@ -119,7 +119,8 @@ ...@@ -119,7 +119,8 @@
* accepted at php-level, which still doesn't guarantee it to be delivered.) * accepted at php-level, which still doesn't guarantee it to be delivered.)
*/ */
function drupal_mail($module, $key, $to, $langcode, $params = array(), $from = NULL, $send = TRUE) { function drupal_mail($module, $key, $to, $langcode, $params = array(), $from = NULL, $send = TRUE) {
$site_mail = config('system.site')->get('mail'); $site_config = config('system.site');
$site_mail = $site_config->get('mail');
if (empty($site_mail)) { if (empty($site_mail)) {
$site_mail = ini_get('sendmail_from'); $site_mail = ini_get('sendmail_from');
} }
...@@ -150,9 +151,10 @@ function drupal_mail($module, $key, $to, $langcode, $params = array(), $from = N ...@@ -150,9 +151,10 @@ function drupal_mail($module, $key, $to, $langcode, $params = array(), $from = N
// To prevent e-mail from looking like spam, the addresses in the Sender and // 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 // Return-Path headers should have a domain authorized to use the originating
// SMTP server. // SMTP server.
$headers['From'] = $headers['Sender'] = $headers['Return-Path'] = $default_from; $headers['Sender'] = $headers['Return-Path'] = $default_from;
$headers['From'] = $site_config->get('name') . ' <' . $default_from . '>';
} }
if ($from) { if ($from && $from != $default_from) {
$headers['From'] = $from; $headers['From'] = $from;
} }
$message['headers'] = $headers; $message['headers'] = $headers;
......
...@@ -76,6 +76,27 @@ public function testCancelMessage() { ...@@ -76,6 +76,27 @@ public function testCancelMessage() {
$this->assertNull(self::$sent_message, 'Message was canceled.'); $this->assertNull(self::$sent_message, 'Message was canceled.');
} }
/**
* Checks for the site name in an auto-generated From: header.
*/
function testFromHeader() {
global $language;
// 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';
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.
drupal_mail('simpletest', 'from_test', 'from_test@example.com', $language);
$this->assertEqual('Drupal <simpletest@example.com>', self::$sent_message['headers']['From']);
}
/** /**
* Concatenate and wrap the e-mail body for plain-text mails. * Concatenate and wrap the e-mail body for plain-text mails.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment