How to include the subject in ALL emails to users and admins

Helpdesk for my helpdesk software

Moderator: mkoch227

DigiMon
Posts: 29
Joined: Sat Aug 12, 2006 12:01 am

How to include the subject in ALL emails to users and admins

Post by DigiMon »

Script URL:
Version of script: 0.94.1
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution: email subject, custom subjects

Write your message below:

I want to do something similar to what is in viewtopic.php?t=1479 but a little bit more than that, and I'm just wondering if this is possible...

Is there a way I can make it so that all subjects in all emails to both customer and staff include the ticket ID and the subject that the user originally entered?

For example:

Let's say a user submits a ticket with subject "Help I can't Log In" and it is assigned ticket ID abcdefg

I would like it so that it's something like this:

USER SUBMITS - Instead of "Your support ticket received" the user gets email with subject "Your ticket abcdefg Help I can't Log In received"

ADMINS NOTIFIED - Instead of "New support ticket submitted" the Hesk admins get email with subject "New ticket abcdefg Help I can't Log In submitted"

USER REPLIES - Instead of "New reply to support ticket" the admins get email with subject "New reply to abcdefg Help I can't Log In"

ADMIN REPLIES - Instead of "New reply to your support ticket" the user gets email with subject "New reply to abcdefg Help I Can't Log In"

Is this possible, or is it asking to do too much?

I tried some code from a much older thread here on this board regarding this topic, but they didn't work quite right.

I am very happy with Hesk the way it is, but if those email subject modifcations were possible I would be totally stoked!

Thanks for any opinions / advice,
Digi
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Well you have all the code you need in the post you mentioned, now just edit the code inside submit_ticket.php, reply_ticket.php and admin_reply_ticket.php to fit your needs.
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
DigiMon
Posts: 29
Joined: Sat Aug 12, 2006 12:01 am

Post by DigiMon »

Using the same technique, I've tried making other changes based on that, but then I run into problems such as the recepient email bouncing.

For example, I can submit a ticket OK as a test user, and the admin notification comes in fine, but the email sent to the user bounces back with this in it:

A message that you sent contained a recipient address that was incorrectly
constructed:


From: missing or malformed local part (expected word or "<")


The message has not been delivered to any recipients.


I tried something a little different, and that resulted in blank subject lines in the email to user.

I'm going to keep experimenting, but for now I can't quite seem to get them all to do what I want - only thing successful so far is the one change from the post I quoted initially at the top here in this thread.
DigiMon
Posts: 29
Joined: Sat Aug 12, 2006 12:01 am

Post by DigiMon »

Here are the new changes I've tried and none have worked quite right. They either result in some subject headers being blank, or some with the sbject text pushed right up against the standard message like "Your support ticket receivedBlahBlahBlah".

admin_reply_ticket.php:

tried changing:
@mail($orig_email,$hesklang['new_reply_staff'],$message,$headers);


to:
@mail($orig_email,$hesklang['new_reply_staff'],$subject,$message,$headers);

and
@mail($orig_email,$hesklang['new_reply_staff'] ,$subject,$message,$headers);

and:
@mail($orig_email,$hesklang['new_reply_staff' ],$subject,$message,$headers);

and:
@mail($orig_email,$hesklang['new_reply_staff '],$subject,$message,$headers);


Tried similar changes to reply_ticket.php and the first @mail line in submit_ticket.php

At this point I've tried everything I can think of and kinda feel like giving up.
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

I see you don't understand how the mail() command works. Usually it accepts 4 parameters:
mail(TO, SUBJECT, MESSAGE, HEADERS)

What you need to do is to REPLACE the SUBJECT (in your example $hesklang['new_reply_staff']) with some other subject. For example change
@mail($orig_email,$hesklang['new_reply_staff'],$message,$headers);

to:

@mail($orig_email,"YOUR NEW SUBJECT...",$message,$headers);

The e-mail subject must always be the second parameter passed to mail() so you need to either remove or edit the original subject. You oly pass 4 parameters to the mail() function meaning you can have only 3 commas inside mail().

For more information on mial() see:
http://www.php.net/manual/en/function.mail.php
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
DigiMon
Posts: 29
Joined: Sat Aug 12, 2006 12:01 am

Post by DigiMon »

Thank you Klemen, but maybe we have a misunderstanding.

My goal is to have the the original subject that the user entered into the original ticket also included in the subject line in all email notifications to both user and staff.

So if user submits a ticket with subject "Upload Problems" then these would be the subject replacements in all email messages:

Instead of user seeing subject:
"Your support ticket received"

Have it be:
"Your support ticket - Upload Problems - received"
or
"Upload Problems ticket received"

And instead of seeing subject:
"New reply to your support ticket"

Have it be:
"New reply to Upload Problems"

Instead of admin seeing subject:
"New reply to support ticket"

Have it be:
"New reply to Upload Problems"

It would be great to have the ticket ID included as well, but if I'm understanding your previous post correctly, there isn't "room" for that information if the user subject is going to be included.

I know you're not taking any custom work, but if you were I'd pay you to make this happen :lol:
DigiMon
Posts: 29
Joined: Sat Aug 12, 2006 12:01 am

Post by DigiMon »

i THINK i got it now... going to test and post results if it works (in case it helps anyone else)

EDIT - nope, nevermind... I can't figure it out :oops:
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Well, you need to look at the code to see which variable holds the ticket subject, then edit e-mail subject to fit your needs.

In submit_ticket.php it's stored in variable $subject, so you could use something like:

@mail($orig_email,"Your ticket - $subject received",$message,$headers);

In reply_ticket.php the subject is stored as $ticket['subject'] (if you use it within quotes leave the single quotes out: $ticket[subject]) and in admin_reply_ticket.php as $orig_subject.
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
newtech
Posts: 5
Joined: Fri May 22, 2009 7:35 pm

Post by newtech »

Did anyone get this to work properly?
ictconsulting
Posts: 21
Joined: Sun Feb 01, 2009 2:21 pm

Did anyone get this to work properly?

Post by ictconsulting »

newtech wrote:Did anyone get this to work properly?
Yes
Last edited by ictconsulting on Fri Jul 03, 2009 11:34 am, edited 1 time in total.
ictconsulting
Posts: 21
Joined: Sun Feb 01, 2009 2:21 pm

Post by ictconsulting »

Got it work.
I added some lines in the language file to disjoint the "do not reply" suffix from the first part of the text strings in the ['ticket_received']... Than I merged some variables together with the $subject in order to pass to the mail command a single variable and get full info instead...


/* Merging the variables */
$subject_full_tr = $hesklang['ticket_received'] . $subject . $hesklang['do_not_reply'];
$subject_full_nts = $hesklang['new_ticket_submitted'] . $subject;

/* Send e-mail */
$headers="From: $hesk_settings[noreply_mail]\n";
$headers.="Reply-to: $hesk_settings[noreply_mail]\n";
$headers.="Return-Path: $hesk_settings[webmaster_mail]\n";
@mail($email,$subject_full_tr,$message,$headers);

......

/* Send e-mail to staff */
$email=implode(',',$admins);
$headers="From: $hesk_settings[noreply_mail]\n";
$headers.="Reply-to: $hesk_settings[noreply_mail]\n";
$headers.="Return-Path: $hesk_settings[webmaster_mail]\n";
@mail($email,$subject_full_nts,$message,$headers);

Works OK ;-)

Now I'm working on the "reply_ticket.php"....
ictconsulting
Posts: 21
Joined: Sun Feb 01, 2009 2:21 pm

Post by ictconsulting »

Here the mods for the other files...

reply_ticket.php

/* Merging the variables */
$subject_full_nrt = $hesklang['new_reply_ticket'] . $ticket['subject'];

/* Send e-mail to staff */
$email=implode(',',$admins);
$headers="From: $hesk_settings[noreply_mail]\n";
$headers.="Reply-to: $hesk_settings[noreply_mail]\n";
$headers.="Return-Path: $hesk_settings[webmaster_mail]\n";
@mail($email,$subject_full_nrt,$message,$headers);
} // End if


admin_reply_ticket.php

/* Merging the variables */
$subject_full_nrs = $hesklang['new_reply_staff'] . $ticket['subject'];

/* Send the e-mail */
$headers="From: $hesk_settings[noreply_mail]\n";
$headers.="Reply-to: $hesk_settings[noreply_mail]\n";
$headers.="Return-Path: $hesk_settings[webmaster_mail]\n";
@mail($orig_email,$subject_full_nrs,$message,$headers);

It shold works as expected.

You should also add a "- " in the related text fields in the language file to separate the merged text strings...

enjoy
hezvale
Posts: 3
Joined: Thu Jun 02, 2011 5:37 am

Re: How to include the subject in ALL emails to users and ad

Post by hezvale »

Hi ictconsulting,

Could you be more specific? In which folder and files do I have to change?
Is there any step? I'm new here.

I just need to add Tracking ID to be in the Email Subject on every ticket raise.

Thanks!
Chris.Marsh
Posts: 2
Joined: Fri Jul 06, 2012 5:33 pm

Re: How to include the subject in ALL emails to users and ad

Post by Chris.Marsh »

Hello Everyone,

I have just downloaded the latest current version 2.3 and we are testing in the lab before we deploy into the live environment. I just need to get the 'TrackingID' into the subject line of the e-mail going to the Customers/Users. Now a lot of what has gone before relates to previous versions and the structure within version 2.3 appears to have changed dramatically and the coding examples don't marry up with the code I am looking at.

OK that said I have achieved what I needed to do when a Customer/User submits a ticket and in the submit_ticket.php I found the following code: -

Code: Select all

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

/* Send e-mail */
hesk_mail($tmpvar['email'],$hesklang['ticket_received'],$msg);
I modified this with the following: -

Code: Select all

/* Format e-mail subject for customer */
$subj = "Ticket " . $trackingID . " has been submitted";

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

/* Send e-mail to customer */
hesk_mail($tmpvar['email'],$subj,$msg);
Now for the admin_reply_ticket.php which is found in the admin folder.
Original Code: -

Code: Select all

/*** 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'],$hesklang['new_reply_staff'],$msg);
Modified with: -

Code: Select all

/*** Send "New reply added" e-mail ***/

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

/* Format e-mail subject for customer */
$subj = "Ticket " . $trackingID . " has been replied to";

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

/* Send e-mail */
hesk_mail($ticket['email'],$subj,$msg);
Regards
Chris
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Re: How to include the subject in ALL emails to users and ad

Post by Klemen »

Just wanted to add that version 2.4 will have an easier way of modifying ticket subjects - all that needs to be done is to modify template subjects inside the language file (en/text.php).

Beta version is available here:
viewtopic.php?f=13&t=4102
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
Post Reply