Merge pull request #2147 from eileenmcnaughton/CRM-13901
[civicrm-core.git] / CRM / Utils / Mail.php
index 389fd2b374dd72ecd680c8ddcd849288ae3d7f1c..e5e56acabb6f254e216be3262549f8b345fb55bd 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -72,7 +72,8 @@ class CRM_Utils_Mail {
     CRM_Utils_Hook::alterMailParams($params);
 
     // check if any module has aborted mail sending
-    if (CRM_Utils_Array::value('abortMailSend', $params) ||
+    if (
+      CRM_Utils_Array::value('abortMailSend', $params) ||
       !CRM_Utils_Array::value('toEmail', $params)
     ) {
       return FALSE;
@@ -93,10 +94,12 @@ class CRM_Utils_Mail {
       $headers = array_merge($headers, $params['headers']);
     }
     $headers['From'] = $params['from'];
-    $headers['To']   = self::formatRFC822Email(CRM_Utils_Array::value('toName', $params),
-      CRM_Utils_Array::value('toEmail', $params),
-      FALSE
-    );
+    $headers['To']   =
+      self::formatRFC822Email(
+        CRM_Utils_Array::value('toName', $params),
+        CRM_Utils_Array::value('toEmail', $params),
+        FALSE
+      );
     $headers['Cc'] = CRM_Utils_Array::value('cc', $params);
     $headers['Bcc'] = CRM_Utils_Array::value('bcc', $params);
     $headers['Subject'] = CRM_Utils_Array::value('subject', $params);
@@ -104,8 +107,10 @@ class CRM_Utils_Mail {
     $headers['Content-Disposition'] = 'inline';
     $headers['Content-Transfer-Encoding'] = '8bit';
     $headers['Return-Path'] = CRM_Utils_Array::value('returnPath', $params);
+
     // CRM-11295: Omit reply-to headers if empty; this avoids issues with overzealous mailservers
     $replyTo = CRM_Utils_Array::value('replyTo', $params, $from);
+
     if (!empty($replyTo)) {
       $headers['Reply-To'] = $replyTo;
     }
@@ -158,28 +163,30 @@ class CRM_Utils_Mail {
     $headers = &$msg->headers($headers);
 
     $to = array($params['toEmail']);
-
-    //get emails from headers, since these are
-    //combination of name and email addresses.
-    if (CRM_Utils_Array::value('Cc', $headers)) {
-      $to[] = CRM_Utils_Array::value('Cc', $headers);
-    }
-    if (CRM_Utils_Array::value('Bcc', $headers)) {
-      $to[] = CRM_Utils_Array::value('Bcc', $headers);
-      unset($headers['Bcc']);
+    $result = null;
+    $mailer =& CRM_Core_Config::getMailer( );
+
+    // Mail_smtp and Mail_sendmail mailers require Bcc anc Cc emails
+    // be included in both $to and $headers['Cc', 'Bcc']
+    if (get_class($mailer) != "Mail_mail") {
+        //get emails from headers, since these are 
+        //combination of name and email addresses.
+        if ( CRM_Utils_Array::value( 'Cc', $headers ) ) {
+            $to[] = CRM_Utils_Array::value( 'Cc', $headers );
+        }
+        if ( CRM_Utils_Array::value( 'Bcc', $headers ) ) {
+            $to[] = CRM_Utils_Array::value( 'Bcc', $headers );
+        }
     }
-
-    $result = NULL;
-    $mailer = CRM_Core_Config::getMailer();
-    CRM_Core_Error::ignoreException();
     if (is_object($mailer)) {
+      CRM_Core_Error::ignoreException();
       $result = $mailer->send($to, $headers, $message);
       CRM_Core_Error::setCallback();
       if (is_a($result, 'PEAR_Error')) {
         $message = self::errorMessage($mailer, $result);
         // append error message in case multiple calls are being made to
         // this method in the course of sending a batch of messages.
-               CRM_Core_Session::setStatus(ts($message), ts('Mailing Error'), 'error');
+        CRM_Core_Session::setStatus($message, ts('Mailing Error'), 'error');
         return FALSE;
       }
       // CRM-10699
@@ -201,7 +208,7 @@ class CRM_Utils_Mail {
     }
 
     $message .= '<li>' . ts('The FROM Email Address configured for this feature may not be a valid sender based on your email service provider rules.') . '</li>' . '</ul>' . '<p>' . ts('Check <a href="%1">this page</a> for more information.', array(
-      1 => CRM_Utils_System::docURL2('user/initial-set-up/email-system-configuration', TRUE))) . '</p>';
+      1 => CRM_Utils_System::docURL2('user/advanced-configuration/email-system-configuration', TRUE))) . '</p>';
 
     return $message;
   }