[mod] add attachment file to email replay sended to customer

Everything related to Hesk - helpdesk software

Moderator: mkoch227

Post Reply
alxik
Posts: 6
Joined: Mon Mar 11, 2024 2:57 pm

[mod] add attachment file to email replay sended to customer

Post by alxik »

Hi,

One small mod from my side, as a lot of customer doesnt "see" link in default template, changed a bit hesk_mail function to attach emails, maybe someone will also use it or it will be added in future release :)

Files needed to change: /inc/email_functions.inc.php
find function hesk_mail and in global variable add $ticket after $hesklang, so it will look that way:

Code: Select all

function hesk_mail($to, $subject, $message, $html_message, $tracking_ID = null) 
{
    global $hesk_settings, $hesklang, $ticket; 
next find // Save ticked ID in a custom header in same function

Code: Select all

        // Save ticket ID in a custom header
        if ($tracking_ID !== null) {
            $mailer->addCustomHeader('X-Hesk-Tracking_ID', $tracking_ID);
        }
and after that code add:

Code: Select all

		if ($hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments'])) {
			
			$att = explode(',', substr($ticket['attachments'], 0, -1));
			
			$hesk_settings['server_path'] = dirname(dirname(__FILE__)).'/'.$hesk_settings['attach_dir'];
			
			// Connect to database
			hesk_dbConnect();
			
			foreach ($att as $myatt) {
				list($att_id, $real_name) = explode('#', $myatt);

				// Get attachment info
				$res = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` WHERE `att_id`='{$att_id}' LIMIT 1");
				if (hesk_dbNumRows($res) != 1)
				{
					hesk_error($hesklang['id_not_valid'].' (att_id)');
				}
				$file = hesk_dbFetchAssoc($res);
				
				// Path of the file on the server
				$realpath = $hesk_settings['server_path'].'/'.$file['saved_name'];
				
				// We should use the real name of file not the filename
				$realname = $real_name;
				
				// Perhaps the file has been deleted?
				if ( ! file_exists($realpath))
				{
					hesk_error($hesklang['attdel']);
				}
				
				// Attach file to email
				$mailer->addAttachment($realpath, $realname);
			}
		}
PS! DISCLAIMER! As i have writed in other theard on that forum - Im not PHP-programmer, studied coding a long time ago in university, but code is working , so sharing it here, maybe it will be added to next version of HESK, if its good :) and english is not my primary language aswell :)
Last edited by alxik on Mon Apr 08, 2024 11:48 am, edited 1 time in total.
Klemen
Site Admin
Posts: 10135
Joined: Fri Feb 11, 2005 4:04 pm

Re: [mod] add attachment file to email replay sended to customer

Post by Klemen »

Thanks for sharing. This has been requested several times before, so I am sure others will find it useful.

I personally am not too keen on adding this before considering all the edge cases (performance with large attachments, security implications, ...) but I hope we get to add it to the original in the future.
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
alxik
Posts: 6
Joined: Mon Mar 11, 2024 2:57 pm

Re: [mod] add attachment file to email replay sended to customer

Post by alxik »

Klemen wrote: Fri Apr 05, 2024 6:00 pm Thanks for sharing. This has been requested several times before, so I am sure others will find it useful.

I personally am not too keen on adding this before considering all the edge cases (performance with large attachments, security implications, ...) but I hope we get to add it to the original in the future.
I also not prefer to send attachments over email (link is better as from my opinion), but end users who is using that system are not familar with links, and it was needed to do :)

PS! changed a bit code, added after $att = explode...

Code: Select all

			$hesk_settings['server_path'] = dirname(dirname(__FILE__)).'/'.$hesk_settings['attach_dir'];
as without that, system will give error when trying to resend notification :)
Post Reply