Suppress error if fakeFile cannot be created.
[civicrm-core.git] / CRM / Utils / Mail.php
index 57453a0ca51c4da1996ceeec9e0b71c952c82f24..78dc6676e7fee081c004891d7d12edea74ba4166 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2016                                |
+ | Copyright CiviCRM LLC (c) 2004-2017                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2016
+ * @copyright CiviCRM LLC (c) 2004-2017
  */
 class CRM_Utils_Mail {
 
@@ -164,7 +164,7 @@ class CRM_Utils_Mail {
     }
 
     // first call the mail alter hook
-    CRM_Utils_Hook::alterMailParams($params);
+    CRM_Utils_Hook::alterMailParams($params, 'singleEmail');
 
     // check if any module has aborted mail sending
     if (!empty($params['abortMailSend']) || empty($params['toEmail'])) {
@@ -257,8 +257,12 @@ class CRM_Utils_Mail {
     $result = NULL;
     $mailer = \Civi::service('pear_mail');
 
-    // Mail_smtp and Mail_sendmail mailers require Bcc anc Cc emails
-    // be included in both $to and $headers['Cc', 'Bcc']
+    // CRM-3795, CRM-7355, CRM-7557, CRM-9058, CRM-9887, CRM-12883, CRM-19173 and others ...
+    // The PEAR library requires different parameters based on the mailer used:
+    // * Mail_mail requires the Cc/Bcc recipients listed ONLY in the $headers variable
+    // * All other mailers require that all be recipients be listed in the $to array AND that
+    //   the Bcc must not be present in $header as otherwise it will be shown to all recipients
+    // ref: https://pear.php.net/bugs/bug.php?id=8047, full thread and answer [2011-04-19 20:48 UTC]
     if (get_class($mailer) != "Mail_mail") {
       // get emails from headers, since these are
       // combination of name and email addresses.
@@ -267,8 +271,10 @@ class CRM_Utils_Mail {
       }
       if (!empty($headers['Bcc'])) {
         $to[] = CRM_Utils_Array::value('Bcc', $headers);
+        unset($headers['Bcc']);
       }
     }
+
     if (is_object($mailer)) {
       $errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
       $result = $mailer->send($to, $headers, $message);