2.4.1 Email Piping Issue

Everything related to Hesk - helpdesk software

Moderator: mkoch227

Post Reply
gijive77
Posts: 3
Joined: Mon Sep 17, 2012 7:00 am

2.4.1 Email Piping Issue

Post by gijive77 »

Hello All,

We have been using HESK for about 2 years and love it. However after recently upgrading from 2.3 to 2.4.1 we have run into an issue with our email piping that was previously working in 2.3.

The issue is that now the Subject of the new ticket email the customer receives looks exactly like this "[#%%TRACK_ID%%] Ticket received: %%SUBJECT%%" - the Tracking ID & Subject are correct in the body of the message with the actual Tracking ID & Subject listed rather than the code for them.

This email piping is used by us to select an option from a custom field to help us internally identify to which email address this was sent. (In our case different company divisions) we use this same file multiple times for each division with only a modification to the custom field value for each . This is still working as it always has since the upgrade, the only issue is with the customer email as stated above.

Below is a copy of the email piping PHP file we are using. Any suggestions as to how to correct the issue to actually display the Tracking ID & Subject are appreciated.

I am not a programmer by the way, so simple explanations are appreciated. Thanks!

(code removed)
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Re: 2.4.1 Email Piping Issue

Post by Klemen »

Here is a guide for changing email subjects in 2.4.1:
http://www.hesk.com/knowledgebase/index.php?article=66

Note that the [#%%TRACK_ID%%] format is required if you wish to support customer email replies to tickets though.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
gijive77
Posts: 3
Joined: Mon Sep 17, 2012 7:00 am

Re: 2.4.1 Email Piping Issue

Post by gijive77 »

Hello,

Thanks for the reply. However I am not sure If I was not clear on the issue.
The issue is not that we wish to change the email subjects, but rather that they are no longer working.

Instead of HESK pulling the actual information it is placing the variable code in the email the client receives. So the client sees this exactly as the subject, regardless of what the actual subject or tracking ID should be:

"[#%%TRACK_ID%%] Ticket received: %%SUBJECT%%"

However in the body of the email the variable information is populated properly and NOT listed as [#%%TRACK_ID%%] or %%SUBJECT%%

We are fine with leaving the default, we just need it to actually populate the information rather than display the variable code.

Thanks.
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Re: 2.4.1 Email Piping Issue

Post by Klemen »

Ah, I understand now what you mean.

I suspect you are using an outdated file - could you try downloading a fresh copy of version 2.4.1 and uploading all files to the server again *except* these ones:
- footer/header
- hesk_settings.inc.php
- language/ folder (if you modified anything inside)
- install/ folder

Does that fix the issue?
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
gijive77
Posts: 3
Joined: Mon Sep 17, 2012 7:00 am

Re: 2.4.1 Email Piping Issue

Post by gijive77 »

Hello,

Thank you for the suggestion, however it still did not work, same issue. I suspect I know where my issue is. I previously posted the email piping file I am using, but it was removed. Can someone please look it over to assist me with how to correct my issue please as my file is needed as I need the email piping specifically to assign a custom field for our tracking purposes.

Code: Select all

#!/usr/local/bin/php -q
<?php
/*******************************************************************************
*  Title: Help Desk Software HESK
*  Version: 2.3 from 15th September 2011
*  Author: Klemen Stirn
*  Website: http://www.hesk.com
********************************************************************************
*  COPYRIGHT AND TRADEMARK NOTICE
*  Copyright 2005-2011 Klemen Stirn. All Rights Reserved.
*  HESK is a registered trademark of Klemen Stirn.

*  The HESK may be used and modified free of charge by anyone
*  AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT.
*  By using this code you agree to indemnify Klemen Stirn from any
*  liability that might arise from it's use.

*  Selling the code for this program, in part or full, without prior
*  written consent is expressly forbidden.

*  Using this code, in part or full, to create derivate work,
*  new scripts or products is expressly forbidden. Obtain permission
*  before redistributing this software over the Internet or in
*  any other medium. In all cases copyright and header must remain intact.
*  This Copyright is in full effect in any country that has International
*  Trade Agreements with the United States of America or
*  with the European Union.

*  Removing any of the copyright notices without purchasing a license
*  is expressly forbidden. To remove HESK copyright notice you must purchase
*  a license for this script. For more information on how to obtain
*  a license please visit the page below:
*  https://www.hesk.com/buy.php
*******************************************************************************/

define('IN_SCRIPT',1);
define('HESK_PATH','/home/public_html/helpdesk/');

/* Get all the required files and functions */
require(HESK_PATH . 'hesk_settings.inc.php');
require(HESK_PATH . 'inc/common.inc.php');
require(HESK_PATH . 'inc/database.inc.php');
require(HESK_PATH . 'inc/email_functions.inc.php');

/* Is this feature enabled? */
if (!$hesk_settings['email_piping'])
{
	die($hesklang['epd']);
}

/* Include email parsing functions */
require(HESK_PATH . 'inc/mail/rfc822_addresses.php');
require(HESK_PATH . 'inc/mail/mime_parser.php');
require(HESK_PATH . 'inc/mail/email_parser.php');

/* parse the incoming email */
$results = parser();

/* Variables */
$tmpvar['name']	    = hesk_input($results['from'][0]['name']) or $tmpvar['name'] = $hesklang['unknown'];
$tmpvar['email']	= hesk_validateEmail($results['from'][0]['address'],'ERR',0);
$tmpvar['category'] = 1;
$tmpvar['priority'] = 3;
$tmpvar['subject']  = hesk_input($results['subject']) or $tmpvar['subject'] = '['.$hesklang['unknown'].']';
$tmpvar['message']  = hesk_input($results['message']);
$_SERVER['REMOTE_ADDR'] = $hesklang['unknown'];
$IS_REPLY = 0;
$trackingID = '';

/* Any important info missing? */
if (!$tmpvar['email'] || !$tmpvar['message'])
{
	return NULL;
}

/* Process the message */
if (!empty($results['encoding']))
{
	if (strtolower($results['encoding']) != strtolower($hesklang['ENCODING']))
    {
		$tmpvar['message']=mb_convert_encoding($tmpvar['message'],$hesklang['ENCODING'],$results['encoding']);
    }
}
$tmpvar['message']=hesk_makeURL($tmpvar['message']);
$tmpvar['message']=nl2br($tmpvar['message']);

/* Process the subject */
if (!empty($results['subject_encoding']))
{
	if (strtolower($results['subject_encoding']) != strtolower($hesklang['ENCODING']))
    {
		$tmpvar['subject']=mb_convert_encoding($tmpvar['subject'],$hesklang['ENCODING'],$results['subject_encoding']);
    }
}

/* Connect to the database */
hesk_dbConnect();

/* Generate tracking ID */
$trackingID = hesk_createID();

/* Process attachments */
$myattachments='';
$num = 0;
if ($hesk_settings['attachments']['use'] && isset($results['attachments'][0]))
{
    foreach ($results['attachments'] as $k => $v)
    {
    	/* Check number of attachments, delete any over max number */
        if ($num == $hesk_settings['attachments']['max_number'])
        {
            break;
        }

        /* Check file extension */
        $myatt['real_name'] = $v['orig_name'];
		$ext = strtolower(strrchr($myatt['real_name'], "."));
		if (!in_array($ext,$hesk_settings['attachments']['allowed_types']))
		{
			continue;
		}

        /* Check file size */
        $myatt['size'] = $v['size'];
		if ($myatt['size'] > ($hesk_settings['attachments']['max_size']*1024))
		{
			continue;
		}

		/* Generate a random file name */
		$myatt['real_name'] = str_replace(array('/','\\','#',',',' '), array('','','','','_'),$myatt['real_name']);
		$useChars='AEUYBDGHJLMNPQRSTVWXZ123456789';
		$tmp = $useChars{mt_rand(0,29)};
		for($j=1;$j<10;$j++)
		{
		    $tmp .= $useChars{mt_rand(0,29)};
		}
	    $myatt['saved_name'] = substr($trackingID . '_' . md5($tmp . $myatt['real_name']), 0, 200) . $ext;

        /* Rename the temporary file */
        rename($v['stored_name'],HESK_PATH.'attachments/'.$myatt['saved_name']);

        /* Insert into database */
        $sql = "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'])."', '".hesk_dbEscape($myatt['size'])."')";
        $result = hesk_dbQuery($sql);
        $myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] .',';

        $num++;
    }
}

/* Delete the temporary files */
deleteAll($results['tempdir']);

/* Auto assign tickets if aplicable */
$history = sprintf($hesklang['thist11'],hesk_date());
$tmpvar['owner'] = 0;

$autoassign_owner = hesk_autoAssignTicket($tmpvar['category']);
if ($autoassign_owner)
{
	$tmpvar['owner'] = $autoassign_owner['id'];
    $history .= sprintf($hesklang['thist10'],hesk_date(),$autoassign_owner['name'].' ('.$autoassign_owner['user'].')');
}

/* Insert the ticket into the database */
foreach ($hesk_settings['custom_fields'] as $k=>$v)
{
	$tmpvar[$k] = '';
}

$sql = "
INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` (
`trackid`,`name`,`email`,`category`,`priority`,`subject`,`message`,`dt`,`lastchange`,`ip`,`status`,`owner`,`attachments`,`history`,`custom1`,`custom2`,`custom3`,`custom4`,`custom5`,`custom6`,`custom7`,`custom8`,`custom9`,`custom10`,`custom11`,`custom12`,`custom13`,`custom14`,`custom15`,`custom16`,`custom17`,`custom18`,`custom19`,`custom20`
)
VALUES (
'".hesk_dbEscape($trackingID)."',
'".hesk_dbEscape($tmpvar['name'])."',
'".hesk_dbEscape($tmpvar['email'])."',
'".hesk_dbEscape($tmpvar['category'])."',
'".hesk_dbEscape($tmpvar['priority'])."',
'".hesk_dbEscape($tmpvar['subject'])."',
'".hesk_dbEscape($tmpvar['message'])."',
NOW(),
NOW(),
'".hesk_dbEscape($_SERVER['REMOTE_ADDR'])."',
'0',
'".hesk_dbEscape($tmpvar['owner'])."',
'".hesk_dbEscape($myattachments)."',
'".hesk_dbEscape($history)."',
'".hesk_dbEscape($tmpvar['custom1'])."',
'".hesk_dbEscape($tmpvar['custom2'])."CUSTOM FIELD MARKER',
'".hesk_dbEscape($tmpvar['custom3'])."',
'".hesk_dbEscape($tmpvar['custom4'])."',
'".hesk_dbEscape($tmpvar['custom5'])."',
'".hesk_dbEscape($tmpvar['custom6'])."',
'".hesk_dbEscape($tmpvar['custom7'])."',
'".hesk_dbEscape($tmpvar['custom8'])."',
'".hesk_dbEscape($tmpvar['custom9'])."',
'".hesk_dbEscape($tmpvar['custom10'])."',
'".hesk_dbEscape($tmpvar['custom11'])."',
'".hesk_dbEscape($tmpvar['custom12'])."',
'".hesk_dbEscape($tmpvar['custom13'])."',
'".hesk_dbEscape($tmpvar['custom14'])."',
'".hesk_dbEscape($tmpvar['custom15'])."',
'".hesk_dbEscape($tmpvar['custom16'])."',
'".hesk_dbEscape($tmpvar['custom17'])."',
'".hesk_dbEscape($tmpvar['custom18'])."',
'".hesk_dbEscape($tmpvar['custom19'])."',
'".hesk_dbEscape($tmpvar['custom20'])."'
)
";

$result = hesk_dbQuery($sql);

/* Ticket array for later use in e-mails */
$ticket = array(
	'name' 		=> hesk_msgToPlain($tmpvar['name'],1),
	'subject' 	=> hesk_msgToPlain($tmpvar['subject'],1),
	'trackid' 	=> $trackingID,
	'category' 	=> $tmpvar['category'],
	'priority' 	=> $tmpvar['priority'],
    'lastreplier' => hesk_msgToPlain($tmpvar['name'],1),
	'message' 	=> hesk_msgToPlain($tmpvar['message'],1),
    'owner'		=> 0,
);

foreach ($hesk_settings['custom_fields'] as $k => $v)
{
	$ticket[$k] = '';
}

/* Format e-mail message for customer */
$msg = hesk_getEmailMessage('new_ticket',$ticket);

/* Send e-mail */
hesk_mail($tmpvar['email'],$hesklang['ticket_received'],$msg);

/*** Need to notify any staff? ***/
/* --> From autoassign? */
if ($tmpvar['owner'] && $autoassign_owner['notify_assigned'])
{
	/* Format e-mail message for staff */
	$msg = hesk_getEmailMessage('ticket_assigned_to_you',$ticket,1);

	/* Send e-mail to staff */
	hesk_mail($autoassign_owner['email'],$hesklang['ticket_assigned_to_you'],$msg);
}

/* --> No autoassign, find and notify appropriate staff */
elseif ( ! $tmpvar['owner'] )
{
	$admins=array();
	$sql = "SELECT `email`,`isadmin`,`categories` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."users` WHERE `notify_new_unassigned`='1'";
	$res = hesk_dbQuery($sql);
	while ($myuser=hesk_dbFetchAssoc($res))
	{
		/* Is this an administrator? */
		if ($myuser['isadmin'])
		{
			$admins[]=$myuser['email'];
			continue;
		}

		/* Not admin, is he allowed this category? */
		$myuser['categories']=explode(',',$myuser['categories']);
		if (in_array($tmpvar['category'],$myuser['categories']))
		{
			$admins[]=$myuser['email'];
			continue;
		}
	}
	if (count($admins)>0)
	{
		/* Format e-mail message for staff */
		$msg = hesk_getEmailMessage('new_ticket_staff',$ticket,1);

		/* Send e-mail to staff */
		$email=implode(',',$admins);
		hesk_mail($email,$hesklang['new_ticket_submitted'],$msg);
	}
} // END not autoassign

return NULL;
?>
As you can see from the above I am only trying to accomplish a basic email piping with a custom field being populated. In this case custom field 2 is being populated with "CUSTOM FIELD MARKER" If there is another way to do this with the new version (2.4.1) any suggestions are appreciated.

Thank you.
Post Reply