Auto assign category based on email address of sender

Everything related to Hesk - helpdesk software

Moderator: mkoch227

Post Reply
cctheboss
Posts: 4
Joined: Mon Mar 16, 2015 6:04 pm

Auto assign category based on email address of sender

Post by cctheboss »

HI,

Desperate help needed...
I am a php beginner, and been trying endlessly to have "POP3 fetching" auto assign the category depending on the email address of the sender.

I have created a few general categories, however, am wanting a few select senders to have their tickets auto assigned to the category of choice.

In the file hesk_pop3.php under the section "optional modifications" it allows to set the category ticket is assigned to.

Code: Select all

// Set category ID where new tickets will be submitted to
$set_category = 1;
Ideally, I would like a conditional to change the category depending on which email address sends the tickets.
for egsample

Code: Select all


if ($sender_email == "info@domain.com" ) {

$set_category = 4;

}else {

$set_category = 1;

}



Please can you help me achieve this.

The category will always be default to "1", but the select few email address's would go to various category as defined.

PLEASE PLEASE HELP!!

clint
Klemen
Site Admin
Posts: 10135
Joined: Fri Feb 11, 2005 4:04 pm

Re: Auto assign category based on email address of sender

Post by Klemen »

In inc/email_functions.inc.php first uncomment line

Code: Select all

$tmpvar['to_email']	= hesk_validateEmail($results['to'][0]['address'],'ERR',0);
Then below that use the $tmpvar['to_email'] variable just as in your example:

Code: Select all

if ($tmpvar['to_email'] == "info@domain.com" ) {

$set_category = 4;

}else {

$set_category = 1;

}
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
cctheboss
Posts: 4
Joined: Mon Mar 16, 2015 6:04 pm

Re: Auto assign category based on email address of sender

Post by cctheboss »

Hey Klemen,

Thanks for the quick reply...

have tried this and did not work.

I did not find the line

Code: Select all

$tmpvar['to_email']   = hesk_validateEmail($results['to'][0]['address'],'ERR',0);
in the "inc/email_functions.inc.php" file, but rather in the "/inc/pipe_functions.inc.php" file.

I uncommented this line, and then added the code as suggested in the /inc/mail/hesk_pop3.php

Have I missed anything?

below are the code for the 3 pages.
/inc/mail/hesk_pop3.php
/inc/pipe_functions.inc.php
/inc/email_functions.inc.php

thanks for your help...
Klemen
Site Admin
Posts: 10135
Joined: Fri Feb 11, 2005 4:04 pm

Re: Auto assign category based on email address of sender

Post by Klemen »

Sorry, that code is indeed inside "/inc/pipe_functions.inc.php", my mistake.

And the "if" code should go in the same file, just below the line $tmpvar['to_email']

No other files need changes (use original ones).



P.s.: no need to copy/paste entire file sources here, I have them all :wink:
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
cctheboss
Posts: 4
Joined: Mon Mar 16, 2015 6:04 pm

Re: Auto assign category based on email address of sender

Post by cctheboss »

Hey Klemen,
Again, thanks for the quick reply...

have tried that aswell, an still defaults to the original "category=1"

Every time the cron job runs the /inc/mail/hesk_pop3.php file, the tickets is created, but always goes to the deafult category as set in /inc/mail/hesk_pop3.php as below.

Code: Select all

//============================================================================//
//                           OPTIONAL MODIFICATIONS                           //
//============================================================================//

// Set category ID where new tickets will be submitted to

$set_category = 1;

// Set ticket priority of new tickets with the following options:
// -1  = use default category priority
//  0  = critical
//  1  = high
//  2  = medium
//  3  = low
$set_priority = -1;
I have added my if statement to the above area but nothing seems to of worked, no matter what I had done.

However with this said, when previouosly trying before I tried your suggestion, I had tried the code below

Code: Select all

if (strpos($results,'@domain.com') !== false) {
    $set_category = 4;
}else{
$set_category = 1;
}
This did not work untill I had added it further down the page "/inc/mail/hesk_pop3.php" under the code below,

Code: Select all

// Parse the incoming email
					$results = parser($message_file);
This seems to have made the change, but something still was not right, as it kept setting the category to "4" no matter what email address had sent the email.

Also the only problem with the bit of code I had tried, was that I needed to change the category for various email address's sending, not just the one.

Is there anything else I am missing?
Not sure if its just me being stupid?? :oops:
Klemen
Site Admin
Posts: 10135
Joined: Fri Feb 11, 2005 4:04 pm

Re: Auto assign category based on email address of sender

Post by Klemen »

Don't edit the hesk_pop3 file, all changes go to the inc/pipe_functoins.inc.php file.

You would edit the hesk_pop3 file directly only if you had several different copies of the file (hesk_pop3_1.php, hesk_pop3_2.php, hesk_pop3_3.php,...) each run by it's own Cron job and each fetching mails from a different POP3 account.

Again, all it takes is changing what I said in a previous post in the inc/pipe_functions.inc.php file. Do not change anything else.

$results is an array, you cannot compare that in an if statement. The actual "to" email is stored in variable $tmpvar['to_email']

Code: Select all

if (stripos($tmpvar['to_email'],'@domain.com') !== false) {
    $set_category = 4;
}else{
$set_category = 1;
}
Please note that teaching PHP is out of the scope of my support. Things like comparing variables and creating if statements is something that should be taught elsewhere.
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
Crammy
Posts: 1
Joined: Tue Mar 17, 2015 12:03 pm

Re: Auto assign category based on email address of sender

Post by Crammy »

Hi,

There is no need to uncomment the '$tmpvar['to_email'] = hesk_validateEmail($results['to'][0]['address'],'ERR',0);' as this is for the TO: field anyway. The best way to add this functionality, append the following line below the mentioned commented line ''$tmpvar['to_email'].....':

Code: Select all

if (stristr($tmpvar['email'],'companyx.com'))  {  $set_category = 2; }
Where category 2 is defined for the companyx.com address. This could be repeat for other companies email domain and/or person address with other categories.

Note: I've used the $tmpvar['email'] to get the senders SMTP email address. The use of stristr with an i has been used for case insensitive domain checking.

Hope this helps?

Craig.
Klemen
Site Admin
Posts: 10135
Joined: Fri Feb 11, 2005 4:04 pm

Re: Auto assign category based on email address of sender

Post by Klemen »

That depends on want to do.

The $tmpvar['email'] variable contains SENDER email so that can be used if you categorize by sender email address.

However, usually you want to categorize by recipient address (for example emails sent to "support@domain.com" go to "support" category, sent to "sales@domain.com" go to "Sales" category, etc...) and that is where the $tmpvar['to_email'] needs to be used.
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
cctheboss
Posts: 4
Joined: Mon Mar 16, 2015 6:04 pm

Re: Auto assign category based on email address of sender

Post by cctheboss »

Hey Craig,

This is exactly was I was looking for. PROBLEM SOLVED!! Youre a legend! :D

Was not needing to have categories setup into departments as it would usually be done.
I had tried the same code you said, but had added it to the wrong page.

So just to clarify,

When a "client" ( sender ) sends in a ticket, I needed certain domains sending the ticket to be auto assigned to category as I define.

So all users from "domain1.com" tickets are added as category = 2,
all users from "domain2.com" tickets are added as category = 3.

thanks to everyone that commented... much appreciated!! 8) :D
Post Reply