email staff owner after ticket is replied to

Helpdesk for my helpdesk software

Moderator: mkoch227

Post Reply
Nathanoj
Posts: 18
Joined: Fri Sep 23, 2011 2:15 pm

email staff owner after ticket is replied to

Post by Nathanoj »

Script URL: ambitechstrous-help.com
Version of script: 2.3
Hosting company: hostgator
URL of phpinfo.php: http://ambitechstrous-help.com/phpjunkyardfiles/
URL of session_test.php: http://ambitechstrous-help.com/phpjunkyardfiles/
What terms did you try when SEARCHING for a solution: staff email; owner email

Write your message below:
Hi Klemen, thanks again for this great software. I use it daily with my team.

My goal is that a reply to a ticket would generate an automatic email and send it to the one who is the ticket "owner" (the one to whom the ticket is assigned). This way, the staff does not have to keep checking back with the site, but would receive an email letting them know when they need to respond.

The feature I'm looking for is similar to what happens when I (as admin) submit a ticket:
1. one automatic email goes to the email for that ticket
2. another one goes to the staff to whom the ticket is assigned.

I thought perhaps copying part of admin_submit_ticket.php and adding it to admin_reply_ticket.php would do the trick. But after a couple hours of banging my head against the wall, I'm giving up on my abilities.

Can you help? Is there something easy that I'm missing?

In case you want to see my attempt at tweaking the code, here's what I added to admin_reply_ticket.php:
(I added it around line 221)

if ($owner && $owner != intval($_SESSION['id']))
{
/* If we don't have info from auto-assign get it from database */
if ( ! isset($autoassign_owner['email']) )
{
/* I updated the last value to 'notify_reply_my' */
$sql = "SELECT `email`,`isadmin`,`categories`,`notify_reply_my` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."users` WHERE `id`=".hesk_dbEscape($ticket['owner']);
$res = hesk_dbQuery($sql);

if (hesk_dbNumRows($res))
{
$autoassign_owner = hesk_dbFetchAssoc($res);
}
}

/* Notify the staff? */
/* I updated the last value to 'notify_reply_my' */
if ($autoassign_owner['notify_reply_my'])
{
/* Format e-mail message */
/* I updated the first value to 'new_reply_by_staff' */
$msg = hesk_getEmailMessage('new_reply_by_staff',$ticket,1);

/* Send e-mail to staff */
hesk_mail($autoassign_owner['email'],$ticket['subject'].' ('.$ticket['name'].')',$msg);
}
}

/* Ticket unassigned, notify everyone that selected to be notified about unassigned tickets */
elseif ( ! $owner)
{
$admins=array();
$sql = "SELECT `email`,`isadmin`,`categories` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."users` WHERE `id`!=".hesk_dbEscape($_SESSION['id'])." AND `notify_new_unassigned`='1'";
$result = hesk_dbQuery($sql);
while ($myuser=hesk_dbFetchAssoc($result))
{
/* 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_reply_by_staff',$ticket,1);

/* Send e-mail to staff */
$email=implode(',',$admins);
hesk_mail($email,$subject,$msg);
}
}

Much thanks
Jon
Nathanoj
Posts: 18
Joined: Fri Sep 23, 2011 2:15 pm

Re: email staff owner after ticket is replied to

Post by Nathanoj »

Oh, and I should mention: I have made sure that the staff I want to receive an email have checked (have a "1" in the database) for the notification option "Client responds to a ticket with owner: Assigned to me"
Klemen
Site Admin
Posts: 10147
Joined: Fri Feb 11, 2005 4:04 pm

Re: email staff owner after ticket is replied to

Post by Klemen »

Hello Jon,

Staff members are indeed notified when a customer replies to their assigned ticket. If other email notifications work fine but this one doesn't, the most obvious solution would be these emails are being blocked by your SPAM filters.

Try adding the "no reply email" address/server IP to your SPAM filter whitelist and see if that helps.
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
Nathanoj
Posts: 18
Joined: Fri Sep 23, 2011 2:15 pm

Re: email staff owner after ticket is replied to

Post by Nathanoj »

Thanks for your quick reply.

I actually had already checked the spam filters (in both email service (gmail) and client (Outlook)) as an earlier step and added the domain to the approved recipients list. And, just to make sure, I created a special test staff account with a separate email and tested the functionality. It was receiving other emails from the site, but there was no message that was sent to the test account, even to the spam filter, to tell it that a ticket it owned had been updated.

Does it make a difference that I typically only reply to a ticket for my staff when I am in the admin login? I never do it by clicking on the link that comes to the creator of the ticket in an email that is specific to that ticket. I don't know if it makes a difference, but my staff are not admins, since I have to limit their access by their project category.

To my only slightly trained eyes, it looked like admin_reply_ticket.php only had the code for one email to be sent? Did I miss something?
/*** Send "New reply added" e-mail ***/

/* Setup ticket message for e-mail */
$ticket['message'] = hesk_msgToPlain($message,1);

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

/* Send e-mail*/
hesk_mail($ticket['email'],$ticket['subject'].' ('.$ticket['lastreplier'].')',$msg);


I hope you don't mind my further questions. I wouldn't keep trying to find a solution if it wasn't such a big part of my business operations.

Thanks so much for your help,
Jon
Klemen
Site Admin
Posts: 10147
Joined: Fri Feb 11, 2005 4:04 pm

Re: email staff owner after ticket is replied to

Post by Klemen »

When staff replies to a ticket the notification is sent to the customer (the person who submitted the ticket), not to other staff members. Hence it is only sent to one address (the customer one).

However, when a customer replies to a ticket from the customer side the notification is sent to the assigned staff.
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
Nathanoj
Posts: 18
Joined: Fri Sep 23, 2011 2:15 pm

Re: email staff owner after ticket is replied to

Post by Nathanoj »

Thanks, that makes sense.

Since I as an admin am usually interacting with the different staff to manage tasks through your ticketing system, I'd love to have it send it to the staff as well when I as an admin reply.

Is it something that would be a code fix you could help with? Or at least let me know if my code (in the first post) is at all close? I'd be willing to pay you! (more than I already did as a registered customer)

Sincerely,
Jon
Klemen
Site Admin
Posts: 10147
Joined: Fri Feb 11, 2005 4:04 pm

Re: email staff owner after ticket is replied to

Post by Klemen »

I didn't go through your code completely, but looks like it's too much of it there.

The correct steps would be to:

1. verify that the ticket is assigned ($ticket['owner'])
2. verify that ticket owner is NOT the same as current user ($_SESSION['id'])
3. if both of above is true get owner email from the database and send an email

See if you can work through these and get it working. I'm out of country until Monday and will check back if you had any problems.
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
Nathanoj
Posts: 18
Joined: Fri Sep 23, 2011 2:15 pm

Re: email staff owner after ticket is replied to

Post by Nathanoj »

Thanks for being willing to walk with me through this! I deleted everything I had added before except for what I have below

I believe #1 & #2 are done with my first line of code, right?...

Code: Select all

if ($owner && $owner != intval($_SESSION['id']))

It's how to accomplish #3 that eludes me. This was my best guess. I copied this from the admin_submit_ticket.php and insert the message type of "notify_reply_my" and changed the first hesk_mail variable to $owner...

Code: Select all

    {
	/* Format e-mail message */
	$msg = hesk_getEmailMessage('notify_reply_my',$ticket,1);

	/* Send e-mail to staff */
	hesk_mail($owner['email'],$ticket['subject'].' ('.$ticket['name'].')',$msg);
    }
Didn't do the trick.

Thanks for being willing to have a look when you return!

Sincerely,
Jon
Klemen
Site Admin
Posts: 10147
Joined: Fri Feb 11, 2005 4:04 pm

Re: email staff owner after ticket is replied to

Post by Klemen »

Actually, the admin_reply_ticket.php uses $ticket['owner'] so you should use that instead of just $owner in #1 and #2.

Then for #3 you can get owner info from the database, something like

Code: Select all

$sql = "SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."users` WHERE `id`=".hesk_dbEscape($ticket['owner']);
$res = hesk_dbQuery($sql);

if (hesk_dbNumRows($res))
{
	$owner = hesk_dbFetchAssoc($res);

	/* Format e-mail message */
	$msg = hesk_getEmailMessage('notify_reply_my',$ticket,1);

	/* Send e-mail to staff */
	hesk_mail($owner['email'],$ticket['subject'].' ('.$ticket['name'].')',$msg);
}
The final code should probably be (didn't test it) something like

Code: Select all

if ($ticket['owner'] && $ticket['owner'] != intval($_SESSION['id']))
{
	$sql = "SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."users` WHERE `id`=".hesk_dbEscape($ticket['owner']);
	$res = hesk_dbQuery($sql);
	if (hesk_dbNumRows($res))
	{
		$owner = hesk_dbFetchAssoc($res);

		/* Format e-mail message */
		$msg = hesk_getEmailMessage('notify_reply_my',$ticket,1);

		/* Send e-mail to staff */
		hesk_mail($owner['email'],$ticket['subject'].' ('.$ticket['name'].')',$msg);
	}
}
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
Nathanoj
Posts: 18
Joined: Fri Sep 23, 2011 2:15 pm

Re: email staff owner after ticket is replied to

Post by Nathanoj »

Thanks, Klemen.

I tried it out and got this message:

"Error:

Invalid email file"

Any ideas?

I just "bought you a drink" as a thank you for your help with my problem. :)

Sincerely,
Jon
Klemen
Site Admin
Posts: 10147
Joined: Fri Feb 11, 2005 4:04 pm

Re: email staff owner after ticket is replied to

Post by Klemen »

Ah, sorry, I was looking at the code for HESK 2.4

Does replacing notify_reply_my with new_reply_by_customer help?
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
Nathanoj
Posts: 18
Joined: Fri Sep 23, 2011 2:15 pm

Re: email staff owner after ticket is replied to

Post by Nathanoj »

You are my hero. That did the trick. I just "bought you a drink" again.

So then will I need to adjust this file when 2.4 comes out?

Thanks,
Jon
Klemen
Site Admin
Posts: 10147
Joined: Fri Feb 11, 2005 4:04 pm

Re: email staff owner after ticket is replied to

Post by Klemen »

Thanks for the drinks!

Actually, version 2.4 will have this enabled by default (ability to notify assigned staff member when another staff member replies to a ticket).
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
Nathanoj
Posts: 18
Joined: Fri Sep 23, 2011 2:15 pm

Re: email staff owner after ticket is replied to

Post by Nathanoj »

Thanks Klemen.
jamesmarshall
Posts: 1
Joined: Tue Sep 10, 2013 8:38 am

Re: email staff owner after ticket is replied to

Post by jamesmarshall »

Hi, what are the files that I need to change? (rows)

Thanks

james
Post Reply