From 6a5de96b7d47f7c99241a183337e8aeb97ce85cb Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 22 Jan 2015 00:01:16 -0500 Subject: [PATCH] #112 SMTP Cc/Bcc fields are working properly --- inc/email_functions.inc.php | 77 +++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 12 deletions(-) diff --git a/inc/email_functions.inc.php b/inc/email_functions.inc.php index 173934ca..30c264a3 100644 --- a/inc/email_functions.inc.php +++ b/inc/email_functions.inc.php @@ -62,7 +62,24 @@ function hesk_notifyCustomerForVerifyEmail($email_template = 'verify_email', $ac $message = str_replace('%%VERIFYURL%%', $activationUrl, $message); $message = str_replace('%%ACTIVATIONKEY%%', $activationKey, $message); - hesk_mail($ticket['email'], $subject, $message); + // Add Cc / Bcc recipents if needed + $ccEmails = array(); + $bccEmails = array(); + foreach ($hesk_settings['custom_fields'] as $k=>$v) { + if ($v['use']) { + if ($v['type'] == 'email' && !empty($ticket[$k])) { + if ($v['value'] == 'cc') { + $emails = explode(',',$ticket[$k]); + array_push($ccEmails, $emails); + } elseif ($v['value'] == 'bcc') { + $emails = explode(',',$ticket[$k]); + array_push($bccEmails, $emails); + } + } + } + } + + hesk_mail($ticket['email'], $subject, $message, $ccEmails, $bccEmails); } @@ -80,8 +97,23 @@ function hesk_notifyCustomer($email_template = 'new_ticket') $subject = hesk_getEmailSubject($email_template,$ticket); $message = hesk_getEmailMessage($email_template,$ticket); + // Add Cc / Bcc recipents if needed + $ccEmails = array(); + $bccEmails = array(); + foreach ($hesk_settings['custom_fields'] as $k=>$v) { + if ($v['use']) { + if ($v['type'] == 'email' && !empty($ticket[$k])) { + if ($v['value'] == 'cc') { + array_push($ccEmails, $ticket[$k]); + } elseif ($v['value'] == 'bcc') { + array_push($bccEmails, $ticket[$k]); + } + } + } + } + // Send e-mail - hesk_mail($ticket['email'], $subject, $message); + hesk_mail($ticket['email'], $subject, $message, $ccEmails, $bccEmails); return true; @@ -275,7 +307,7 @@ function hesk_validEmails() } // END hesk_validEmails() -function hesk_mail($to,$subject,$message) +function hesk_mail($to,$subject,$message,$cc=array(),$bcc=array()) { global $hesk_settings, $hesklang; @@ -307,6 +339,14 @@ function hesk_mail($to,$subject,$message) { // Set additional headers $headers = "From: $hesk_settings[from_header]\n"; + if (count($cc) > 0) + { + $headers .= "Cc: ".implode(',',$cc); + } + if (count($bcc) > 0) + { + $headers .= "Bcc: ".implode(',',$bcc); + } $headers.= "Reply-To: $hesk_settings[from_header]\n"; $headers.= "Return-Path: $hesk_settings[webmaster_mail]\n"; $headers.= "Date: " . date(DATE_RFC2822) . "\n"; @@ -337,15 +377,28 @@ function hesk_mail($to,$subject,$message) // Send the e-mail using SMTP $to_arr = explode(',',$to); - if ( ! $smtp->SendMessage($hesk_settings['noreply_mail'], $to_arr, array( - "From: $hesk_settings[from_header]", - "To: $to", - "Reply-To: $hesk_settings[from_header]", - "Return-Path: $hesk_settings[webmaster_mail]", - "Subject: " . $subject, - "Date: " . date(DATE_RFC2822), - "Content-Type: text/plain; charset=" . $hesklang['ENCODING'] - ), $message)) + + + $headersArray = array( + "From: $hesk_settings[from_header]", + "To: $to", + "Reply-To: $hesk_settings[from_header]", + "Return-Path: $hesk_settings[webmaster_mail]", + "Subject: " . $subject, + "Date: " . date(DATE_RFC2822), + "Content-Type: text/plain; charset=" . $hesklang['ENCODING'] + ); + if (count($cc) > 0) + { + array_push($headersArray,"Cc: ".implode(',',$cc)); + } + if (count($bcc) > 0) + { + array_push($headersArray,"Bcc: ".implode(',',$bcc)); + } + + + if ( ! $smtp->SendMessage($hesk_settings['noreply_mail'], $to_arr, $headersArray, $message)) { // Suppress errors unless we are in debug mode if ($hesk_settings['debug_mode'])