#146 Attachments can now be embedded directly into emails
Only tested SMTP, still need to check PHP mail() and Mailgun
This commit is contained in:
parent
2ddb61bb55
commit
190b3ff475
@ -197,7 +197,7 @@ if ($hesk_settings['attachments']['use'] && !empty($attachments))
|
||||
foreach ($attachments as $myatt)
|
||||
{
|
||||
hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` (`ticket_id`,`saved_name`,`real_name`,`size`) VALUES ('".hesk_dbEscape($trackingID)."','".hesk_dbEscape($myatt['saved_name'])."','".hesk_dbEscape($myatt['real_name'])."','".intval($myatt['size'])."')");
|
||||
$myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] .',';
|
||||
$myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] . '#' . $myatt['saved_name'] .',';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -401,7 +401,7 @@ if (isset($_POST['notemsg']) && hesk_token_check('POST'))
|
||||
foreach ($attachments as $myatt)
|
||||
{
|
||||
hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` (`ticket_id`,`saved_name`,`real_name`,`size`,`type`) VALUES ('".hesk_dbEscape($trackingID)."','".hesk_dbEscape($myatt['saved_name'])."','".hesk_dbEscape($myatt['real_name'])."','".intval($myatt['size'])."', '1')");
|
||||
$myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] .',';
|
||||
$myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] . '#' . $myatt['saved_name'] .',';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ function hesk_validEmails()
|
||||
|
||||
function hesk_mail($to,$subject,$message,$htmlMessage,$cc=array(),$bcc=array())
|
||||
{
|
||||
global $hesk_settings, $hesklang, $modsForHesk_settings;
|
||||
global $hesk_settings, $hesklang, $modsForHesk_settings, $ticket;
|
||||
|
||||
// Demo mode
|
||||
if ( defined('HESK_DEMO') )
|
||||
@ -399,6 +399,11 @@ function hesk_mail($to,$subject,$message,$htmlMessage,$cc=array(),$bcc=array())
|
||||
{
|
||||
$postfields['html'] = $htmlMessage;
|
||||
}
|
||||
if ($hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments']) && $ticket['attachments'] != '' )
|
||||
{
|
||||
processDirectAttachments('mailgun', $postfields);
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
@ -421,7 +426,6 @@ function hesk_mail($to,$subject,$message,$htmlMessage,$cc=array(),$bcc=array())
|
||||
$message .= "--".$boundary."\n";
|
||||
$message .= "Content-Type: text/html; charset=".$hesklang['ENCODING']."\n\n";
|
||||
$message .= $htmlMessage."\n\n";
|
||||
$message .= "--".$boundary."--";
|
||||
}
|
||||
|
||||
// Use PHP's mail function
|
||||
@ -444,6 +448,15 @@ function hesk_mail($to,$subject,$message,$htmlMessage,$cc=array(),$bcc=array())
|
||||
$headers.= "Date: " . date(DATE_RFC2822) . "\n";
|
||||
$headers.= "Content-Type: multipart/alternative;boundary=".$boundary;
|
||||
|
||||
// Add attachments if necessary
|
||||
if ($modsForHesk_settings['attachments'] && $hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments']))
|
||||
{
|
||||
$message .= processDirectAttachments('phpmail', NULL, $boundary);
|
||||
}
|
||||
|
||||
//-- Close the email
|
||||
$message .= "--".$boundary."--";
|
||||
|
||||
// Send using PHP mail() function
|
||||
ob_start();
|
||||
mail($to,$subject,$message,$headers);
|
||||
@ -490,7 +503,14 @@ function hesk_mail($to,$subject,$message,$htmlMessage,$cc=array(),$bcc=array())
|
||||
array_push($headersArray,"Bcc: ".implode(',',$bcc));
|
||||
}
|
||||
|
||||
// Add attachments if necessary
|
||||
if ($modsForHesk_settings['attachments'] && $hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments']))
|
||||
{
|
||||
$message .= processDirectAttachments('smtp', NULL, $boundary);
|
||||
}
|
||||
|
||||
//-- Close the email
|
||||
$message .= "--".$boundary."--";
|
||||
if ( ! $smtp->SendMessage($hesk_settings['noreply_mail'], $to_arr, $headersArray, $message))
|
||||
{
|
||||
// Suppress errors unless we are in debug mode
|
||||
@ -665,7 +685,7 @@ function hesk_getEmailMessage($eml_file, $ticket, $is_admin=0, $is_ticket=1, $ju
|
||||
|
||||
function hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message, $isForHtml = 0)
|
||||
{
|
||||
global $hesk_settings, $hesklang;
|
||||
global $hesk_settings, $hesklang, $modsForHesk_settings;
|
||||
|
||||
/* Return just the message without any processing? */
|
||||
if ($just_message)
|
||||
@ -784,26 +804,31 @@ function hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message
|
||||
$msg = str_replace('%%MESSAGE%%',$ticket['message'],$msg);
|
||||
}
|
||||
|
||||
// Add direct links to any attachments at the bottom of the email message
|
||||
// Add direct links to any attachments at the bottom of the email message OR add them as attachments, depending on the settings
|
||||
// if ($modsForHesk_settings['attachments'] == 'inline' (other is 'attachment') {...}
|
||||
if ($hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments']) )
|
||||
{
|
||||
if ($isForHtml) {
|
||||
$msg .= "<br><br><br>" . $hesklang['fatt'];
|
||||
} else {
|
||||
$msg .= "\n\n\n" . $hesklang['fatt'];
|
||||
if (!$modsForHesk_settings['attachments']) {
|
||||
if ($isForHtml) {
|
||||
$msg .= "<br><br><br>" . $hesklang['fatt'];
|
||||
} else {
|
||||
$msg .= "\n\n\n" . $hesklang['fatt'];
|
||||
}
|
||||
|
||||
$att = explode(',', substr($ticket['attachments'], 0, -1));
|
||||
foreach ($att as $myatt)
|
||||
{
|
||||
list($att_id, $att_name, $saved_name) = explode('#', $myatt);
|
||||
if ($isForHtml) {
|
||||
$msg .= "<br><br>" . $att_name . "<br>";
|
||||
} else {
|
||||
$msg .= "\n\n" . $att_name . "\n";
|
||||
}
|
||||
$msg .= $hesk_settings['hesk_url'] . '/download_attachment.php?att_id='.$att_id.'&track='.$ticket['trackid'].$hesk_settings['e_param'];
|
||||
}
|
||||
}
|
||||
|
||||
$att = explode(',', substr($ticket['attachments'], 0, -1));
|
||||
foreach ($att as $myatt)
|
||||
{
|
||||
list($att_id, $att_name) = explode('#', $myatt);
|
||||
if ($isForHtml) {
|
||||
$msg .= "<br><br>" . $att_name . "<br>";
|
||||
} else {
|
||||
$msg .= "\n\n" . $att_name . "\n";
|
||||
}
|
||||
$msg .= $hesk_settings['hesk_url'] . '/download_attachment.php?att_id='.$att_id.'&track='.$ticket['trackid'].$hesk_settings['e_param'];
|
||||
}
|
||||
// If attachments setting is set to 1, we'll add the attachments separately later; otherwise we'll duplicate the number of attachments.
|
||||
}
|
||||
|
||||
// For customer notifications: if we allow email piping/pop 3 fetching and
|
||||
@ -816,3 +841,33 @@ function hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
// $postfields is only required for mailgun.
|
||||
// $boundary is only required for PHP/SMTP
|
||||
function processDirectAttachments($emailMethod, $postfields = NULL, $boundary = '', $isHtml = false) {
|
||||
global $hesk_settings, $ticket;
|
||||
|
||||
$att = explode(',', substr($ticket['attachments'], 0, -1));
|
||||
// if using mailgun, add each attachment to the array
|
||||
if ($emailMethod == 'mailgun') {
|
||||
$i = 0;
|
||||
foreach ($att as $myatt) {
|
||||
list($att_id, $att_name, $saved_name) = explode('#', $myatt);
|
||||
$postfields['attachment['.$i.']'] = '@'.HESK_PATH.$hesk_settings['attach_dir'].'/'.$saved_name;
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
$attachments = '';
|
||||
foreach ($att as $myatt) {
|
||||
list($att_id, $att_name, $saved_name) = explode('#', $myatt);
|
||||
$attachments .= "\n\n" . "--".$boundary."\n";
|
||||
$attachments .= "Content-Type: application/octet-stream; name=\"".$att_name."\" \n";
|
||||
$attachments .= "Content-Disposition: attachment\n";
|
||||
$attachments .= "Content-Transfer-Encoding: base64\n\n";
|
||||
$attachmentBinary = file_get_contents(HESK_PATH.$hesk_settings['attach_dir'].'/'.$saved_name);
|
||||
$attcontents = chunk_split(base64_encode($attachmentBinary));
|
||||
$attachments .= $attcontents."\n\n";
|
||||
}
|
||||
return $attachments;
|
||||
}
|
||||
}
|
||||
|
@ -37,4 +37,7 @@ $modsForHesk_settings['mailgun_domain'] = '';
|
||||
$modsForHesk_settings['use_bootstrap_theme'] = 1;
|
||||
|
||||
//-- Default value for new Knowledgebase article: 0 = Published, 1 = Private, 2 = Draft
|
||||
$modsForHesk_settings['new_kb_article_visibility'] = 0;
|
||||
$modsForHesk_settings['new_kb_article_visibility'] = 0;
|
||||
|
||||
//-- Setting for adding attachments to email messages. Either 0 for default-HESK behavior, or 1 to send as attachments
|
||||
$modsForHesk_settings['attachments'] = 0;
|
@ -187,7 +187,7 @@ if ($hesk_settings['attachments']['use'] && !empty($attachments))
|
||||
foreach ($attachments as $myatt)
|
||||
{
|
||||
hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` (`ticket_id`,`saved_name`,`real_name`,`size`) VALUES ('{$trackingID}','".hesk_dbEscape($myatt['saved_name'])."','".hesk_dbEscape($myatt['real_name'])."','".intval($myatt['size'])."')");
|
||||
$myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] .',';
|
||||
$myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] . '#' . $myatt['saved_name'] .',';
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user