@ -35,8 +35,6 @@
/* Check if this is a valid include */
if (!defined('IN_SCRIPT')) {die('Invalid attempt');}
require_once(HESK_PATH . 'modsForHesk_settings.inc.php');
/* Get includes for SMTP */
if ($hesk_settings['smtp'])
{
@ -59,6 +57,7 @@ function hesk_notifyCustomerForVerifyEmail($email_template = 'verify_email', $ac
// Format email subject and message
$subject = hesk_getEmailSubject($email_template, $ticket);
$message = hesk_getEmailMessage($email_template, $ticket);
$htmlMessage = hesk_getHtmlMessage($email_template, $ticket);
$activationUrl = $hesk_settings['hesk_url'] . '/verifyemail.php?key=%%ACTIVATIONKEY%%';
$message = str_replace('%%VERIFYURL%%', $activationUrl, $message);
$message = str_replace('%%ACTIVATIONKEY%%', $activationKey, $message);
@ -80,7 +79,7 @@ function hesk_notifyCustomerForVerifyEmail($email_template = 'verify_email', $ac
}
}
hesk_mail($ticket['email'], $subject, $message, $ccEmails, $bccEmails);
hesk_mail($ticket['email'], $subject, $message, $htmlMessage, $ ccEmails, $bccEmails);
}
@ -105,6 +104,7 @@ function hesk_notifyCustomer($email_template = 'new_ticket')
// Format email subject and message
$subject = hesk_getEmailSubject($email_template,$ticket);
$message = hesk_getEmailMessage($email_template,$ticket);
$htmlMessage = hesk_getHtmlMessage($email_template,$ticket);
// Add Cc / Bcc recipents if needed
$ccEmails = array();
@ -122,7 +122,7 @@ function hesk_notifyCustomer($email_template = 'new_ticket')
}
// Send e-mail
hesk_mail($ticket['email'], $subject, $message, $ccEmails, $bccEmails);
hesk_mail($ticket['email'], $subject, $message, $htmlMessage, $ ccEmails, $bccEmails);
// Reset the language if it was changed
if ($changedLanguage)
@ -168,9 +168,10 @@ function hesk_notifyAssignedStaff($autoassign_owner, $email_template, $type = 'n
/* Format email subject and message for staff */
$subject = hesk_getEmailSubject($email_template,$ticket);
$message = hesk_getEmailMessage($email_template,$ticket,1);
$htmlMessage = hesk_getHtmlMessage($email_template,$ticket,1);
/* Send email to staff */
hesk_mail($autoassign_owner['email'], $subject, $message);
hesk_mail($autoassign_owner['email'], $subject, $message, $htmlMessage );
/* Reset language to original one */
hesk_resetLanguage();
@ -238,7 +239,7 @@ function hesk_notifyStaff($email_template,$sql_where,$is_ticket=1)
if ($current_language != 'NONE')
{
/* Send e-mail to staff */
hesk_mail(implode(',',$recipients), $subject, $message );
hesk_mail(implode(',',$recipients), $subject, $message, $htmlMessage );
/* Reset list of email addresses */
$recipients = array();
@ -250,6 +251,7 @@ function hesk_notifyStaff($email_template,$sql_where,$is_ticket=1)
/* Format staff email subject and message for this language */
$subject = hesk_getEmailSubject($email_template,$ticket);
$message = hesk_getEmailMessage($email_template,$ticket,$is_ticket);
$htmlMessage = hesk_getHtmlMessage($email_template,$ticket,$is_ticket);
/* Add email to the recipients list */
$recipients[] = $admin['email'];
@ -260,7 +262,7 @@ function hesk_notifyStaff($email_template,$sql_where,$is_ticket=1)
}
/* Send email messages to the remaining staff */
hesk_mail(implode(',',$recipients), $subject, $message );
hesk_mail(implode(',',$recipients), $subject, $message, $htmlMessage );
/* Reset language to original one */
hesk_resetLanguage();
@ -322,7 +324,7 @@ function hesk_validEmails()
} // END hesk_validEmails()
function hesk_mail($to,$subject,$message,$cc=array(),$bcc=array())
function hesk_mail($to,$subject,$message,$htmlMessage,$ cc=array(),$bcc=array())
{
global $hesk_settings, $hesklang, $modsForHesk_settings;
@ -366,14 +368,27 @@ function hesk_mail($to,$subject,$message,$cc=array(),$bcc=array())
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,
array(
$postfields = array(
'from' => $hesk_settings['from_header'],
'to' => $to,
'h:Reply-To'=> $hesk_settings['from_header'],
'subject' => $subject,
'text' => $message
));
);
if (count($cc) > 0)
{
$postfields['cc'] = implode(',',$cc);
}
if (count($bcc) > 0)
{
$postfields['bcc'] = implode(',',$bcc);
}
if ($modsForHesk_settings['html_emails'])
{
$postfields['html'] = $htmlMessage;
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec($ch);
curl_close($ch);
@ -383,11 +398,31 @@ function hesk_mail($to,$subject,$message,$cc=array(),$bcc=array())
return (strlen($tmp)) ? $tmp : true;
}
$boundary = sha1(uniqid());
//Prepare the message for HTML or non-html
if ($modsForHesk_settings['html_emails'])
{
$plaintextMessage = $message;
$message = "--".$boundary."\n";
$message .= "Content-Type: text/plain; charset=".$hesklang['ENCODING']."\n\n";
$message .= $plaintextMessage."\n\n";
$message .= "--".$boundary."\n";
$message .= "Content-Type: text/html; charset=".$hesklang['ENCODING']."\n\n";
$message .= $htmlMessage."\n\n";
$message .= "--".$boundary."--";
}
// Use PHP's mail function
elseif ( ! $hesk_settings['smtp'])
if ( ! $hesk_settings['smtp'])
{
// Set additional headers
$headers = "From: $hesk_settings[from_header]\n";
$headers = '';
if ($modsForHesk_settings['html_emails'])
{
$headers .= "MIME-Version: 1.0\n";
}
$headers .= "From: $hesk_settings[from_header]\n";
if (count($cc) > 0)
{
$headers .= "Cc: ".implode(',',$cc);
@ -399,7 +434,10 @@ function hesk_mail($to,$subject,$message,$cc=array(),$bcc=array())
$headers.= "Reply-To: $hesk_settings[from_header]\n";
$headers.= "Return-Path: $hesk_settings[webmaster_mail]\n";
$headers.= "Date: " . date(DATE_RFC2822) . "\n";
$headers.= "Content-Type: text/plain; charset=" . $hesklang['ENCODING'];
if ($modsForHesk_settings['html_emails'])
{
$headers.= "Content-Type: multipart/alternative;boundary=".$boundary;
}
// Send using PHP mail() function
ob_start();
@ -427,16 +465,22 @@ function hesk_mail($to,$subject,$message,$cc=array(),$bcc=array())
// Send the e-mail using SMTP
$to_arr = explode(',',$to);
$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']
"Date: " . date(DATE_RFC2822)
);
if ($modsForHesk_settings['html_emails'])
{
array_push($headersArray,"MIME-Version: 1.0\n");
array_push($headersArray,"Content-Type: multipart/alternative;boundary=".$boundary."\n");
} else
{
array_push($headersArray,"Content-Type: text/plain; charset=" . $hesklang['ENCODING']);
}
if (count($cc) > 0)
{
array_push($headersArray,"Cc: ".implode(',',$cc));
@ -548,6 +592,40 @@ function hesk_getEmailSubject($eml_file, $ticket='', $is_ticket=1, $strip=0)
} // hesk_getEmailSubject()
function hesk_getHtmlMessage($eml_file, $ticket, $is_admin=0, $is_ticket=1, $just_message=0)
{
global $hesk_settings, $hesklang, $modsForHesk_settings;
// Demo mode
if ( defined('HESK_DEMO') || !$modsForHesk_settings['html_emails'])
{
return '';
}
// We won't do validation here, as hesk_getEmailMessage will be called which handles validation.
// Get email template
$original_eml_file = $eml_file;
$eml_file = 'language/'.$hesk_settings['languages'][$hesk_settings['language']]['folder'].'/emails/html/'.$original_eml_file.'.txt';
$plain_eml_file = 'language/'.$hesk_settings['languages'][$hesk_settings['language']]['folder'].'/emails/'.$original_eml_file.'.txt';
if (file_exists(HESK_PATH.$eml_file))
{
$msg = file_get_contents(HESK_PATH.$eml_file);
}
elseif (file_exists(HESK_PATH.$plain_eml_file))
{
$msg = file_get_contents(HESK_PATH.$plain_eml_file);
}
else
{
hesk_error($hesklang['emfm'].': '.$eml_file);
}
//Perform logic common between hesk_getEmailMessage and hesk_getHtmlMessage
$msg = hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message);
return $msg;
}
function hesk_getEmailMessage($eml_file, $ticket, $is_admin=0, $is_ticket=1, $just_message=0)
{
@ -580,6 +658,15 @@ function hesk_getEmailMessage($eml_file, $ticket, $is_admin=0, $is_ticket=1, $ju
hesk_error($hesklang['emfm'].': '.$eml_file);
}
$msg = hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message);
return $msg;
} // END hesk_getEmailMessage
function hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message)
{
global $hesk_settings, $hesklang;
/* Return just the message without any processing? */
if ($just_message)
{
@ -707,5 +794,4 @@ function hesk_getEmailMessage($eml_file, $ticket, $is_admin=0, $is_ticket=1, $ju
}
return $msg;
} // END hesk_getEmailMessage
}