From c69abeeed2701e9a43130ccb9e3f00c070ee71de Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Sat, 28 Apr 2018 15:00:31 +0100 Subject: [PATCH] On some servers mail() fails when 'Cc' or 'Bcc' headers are defined but empty --- CRM/Utils/Mail.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CRM/Utils/Mail.php b/CRM/Utils/Mail.php index bebd05169c..c56d9556e0 100644 --- a/CRM/Utils/Mail.php +++ b/CRM/Utils/Mail.php @@ -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'; -- 2.25.1