On some servers mail() fails when 'Cc' or 'Bcc' headers are defined but empty
authorMatthew Wire <devel@mrwire.co.uk>
Sat, 28 Apr 2018 14:00:31 +0000 (15:00 +0100)
committerMatthew Wire <devel@mrwire.co.uk>
Tue, 8 May 2018 06:47:23 +0000 (07:47 +0100)
CRM/Utils/Mail.php

index bebd05169c5d21a3d796c64636940cb4bd03f8bd..c56d9556e0d7a384308399abd4cf9758d666a083 100644 (file)
@@ -203,8 +203,15 @@ class CRM_Utils_Mail {
       CRM_Utils_Array::value('toEmail', $params),
       FALSE
     );
-    $headers['Cc'] = CRM_Utils_Array::value('cc', $params);
-    $headers['Bcc'] = CRM_Utils_Array::value('bcc', $params);
+
+    // On some servers mail() fails when 'Cc' or 'Bcc' headers are defined but empty.
+    foreach (['Cc', 'Bcc'] as $optionalHeader) {
+      $headers[$optionalHeader] = CRM_Utils_Array::value(strtolower($optionalHeader), $params);
+      if (empty($headers[$optionalHeader])) {
+        unset($headers[$optionalHeader]);
+      }
+    }
+
     $headers['Subject'] = CRM_Utils_Array::value('subject', $params);
     $headers['Content-Type'] = $htmlMessage ? 'multipart/mixed; charset=utf-8' : 'text/plain; charset=utf-8';
     $headers['Content-Disposition'] = 'inline';