From 2919d712b2ce7849a2532a08a3a1daaafe7f53ae Mon Sep 17 00:00:00 2001
From: Bob Vincent <bobvin@pillars.net>
Date: Thu, 28 Apr 2011 20:38:43 -0400
Subject: [PATCH] Issue #209672 by dshaw, theborg, cburschka, Rob Loach, carlos8f, gdud, pillarsdotnet: Use site name in From: headers for system e-mails.

---
 includes/mail.inc |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/includes/mail.inc b/includes/mail.inc
index a778ac551c836daa186c3d263d97938e27c09fc2..d35f5037ee353945d8679aa7c441165fa2a6dffb 100644
--- a/includes/mail.inc
+++ b/includes/mail.inc
@@ -100,15 +100,21 @@ function drupal_mail($module, $key, $to, $language, $params = array(), $from = N
     'Content-Transfer-Encoding' => '8Bit',
     'X-Mailer'                  => 'Drupal'
   );
-  if ($default_from) {
+  if (valid_email_address($default_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. Errors-To is redundant, but shouldn't hurt.
-    $headers['From'] = $headers['Sender'] = $headers['Return-Path'] = $headers['Errors-To'] = $default_from;
+    $headers['Sender'] = $headers['Return-Path'] = $headers['Errors-To'] = $default_from;
   }
   if ($from) {
     $headers['From'] = $from;
   }
+  else {
+    // Use site name in default From address.
+    $site_name = variable_get('site_name', 'Drupal');
+    $site_name = str_replace('"', '', mime_header_encode($site_name));
+    $headers['From'] = '"' . $site_name . '" <' . $default_from . '>';
+  }
   $message['headers'] = $headers;
 
   // Build the e-mail (get subject and body, allow additional headers) by
-- 
1.7.1

