diff --git a/includes/mail.inc b/includes/mail.inc index 7a1d29ed..2c173a2 100644 --- a/includes/mail.inc +++ b/includes/mail.inc @@ -104,8 +104,8 @@ define('MAIL_LINE_ENDINGS', isset($_SERVER['WINDIR']) || strpos($_SERVER['SERVER * Language object to use to compose the e-mail. * @param $params * Optional parameters to build the e-mail. - * @param $from - * Sets From to this value, if given. + * @param string|null $reply + * Optional e-mail address to be used to answer. * @param $send * If TRUE, drupal_mail() will call drupal_mail_system()->mail() to deliver * the message, and store the result in $message['result']. Modules @@ -119,8 +119,8 @@ define('MAIL_LINE_ENDINGS', isset($_SERVER['WINDIR']) || strpos($_SERVER['SERVER * written to the watchdog. (Success means nothing more than the message being * accepted at php-level, which still doesn't guarantee it to be delivered.) */ -function drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE) { - $default_from = variable_get('site_mail', ini_get('sendmail_from')); +function drupal_mail($module, $key, $to, $language, $params = array(), $reply = NULL, $send = TRUE) { + $from = variable_get('site_mail', ini_get('sendmail_from')); // Bundle up the variables into a structured array for altering. $message = array( @@ -128,7 +128,8 @@ function drupal_mail($module, $key, $to, $language, $params = array(), $from = N 'module' => $module, 'key' => $key, 'to' => $to, - 'from' => isset($from) ? $from : $default_from, + 'from' => $from, + 'reply-to' => isset($reply) ? $reply : $from, 'language' => $language, 'params' => $params, 'send' => TRUE, @@ -143,14 +144,14 @@ function drupal_mail($module, $key, $to, $language, $params = array(), $from = N 'Content-Transfer-Encoding' => '8Bit', 'X-Mailer' => 'Drupal' ); - if ($default_from) { + if ($from) { // 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['From'] = $headers['Sender'] = $headers['Return-Path'] = $from; } - if ($from) { - $headers['From'] = $from; + if ($reply) { + $headers['Reply-to'] = $reply; } $message['headers'] = $headers; diff --git a/modules/contact/contact.test b/modules/contact/contact.test index 6693b57..3b795d5 100644 --- a/modules/contact/contact.test +++ b/modules/contact/contact.test @@ -173,7 +173,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase { $bar_autoreply = $this->randomName(40); $this->addCategory('foo', 'foo@example.com', $foo_autoreply, FALSE); $this->addCategory('bar', 'bar@example.com', $bar_autoreply, FALSE); - $this->addCategory('no_autoreply', 'bar@example.com', '', FALSE); + $this->addCategory('no_autoreply', 'no_autoreply@example.com', '', FALSE); // Test the auto-reply for category 'foo'. $email = $this->randomName(32) . '@example.com'; @@ -181,7 +181,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase { $this->submitContact($this->randomName(16), $email, $subject, 2, $this->randomString(128)); // We are testing the auto-reply, so there should be one e-mail going to the sender. - $captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'from' => 'foo@example.com')); + $captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'reply-to' => 'foo@example.com')); $this->assertEqual(count($captured_emails), 1, 'Auto-reply e-mail was sent to the sender for category "foo".', 'Contact'); $this->assertEqual($captured_emails[0]['body'], drupal_html_to_text($foo_autoreply), 'Auto-reply e-mail body is correct for category "foo".', 'Contact'); @@ -190,14 +190,14 @@ class ContactSitewideTestCase extends DrupalWebTestCase { $this->submitContact($this->randomName(16), $email, $this->randomString(64), 3, $this->randomString(128)); // Auto-reply for category 'bar' should result in one auto-reply e-mail to the sender. - $captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'from' => 'bar@example.com')); + $captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'reply-to' => 'bar@example.com')); $this->assertEqual(count($captured_emails), 1, 'Auto-reply e-mail was sent to the sender for category "bar".', 'Contact'); $this->assertEqual($captured_emails[0]['body'], drupal_html_to_text($bar_autoreply), 'Auto-reply e-mail body is correct for category "bar".', 'Contact'); // Verify that no auto-reply is sent when the auto-reply field is left blank. $email = $this->randomName(32) . '@example.com'; $this->submitContact($this->randomName(16), $email, $this->randomString(64), 4, $this->randomString(128)); - $captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'from' => 'no_autoreply@example.com')); + $captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email, 'reply-to' => 'no_autoreply@example.com')); $this->assertEqual(count($captured_emails), 0, 'No auto-reply e-mail was sent to the sender for category "no-autoreply".', 'Contact'); }