Jump to content

Send Ticket Open Email only if Client


craigedmonds

Recommended Posts

The world can send us an email to our support address, which is fine. This means ANYONE can email us. Again, thats fine.

However, I ONLY want to send an autoresponder ticket open reply to those who are registered clients in the system.

The problem that we are having at the moment is that spammers/cold emailers will send an email to our support address and of course we send back a "ticket opened" email, which usually ends up not being delivered, resulting in our mails getting blocked to legitainte users.

Is there a hook I can "hook into" to stop sending the email if the email is not a  client?

FOR EXAMPLE: If spammer@gmail.com send an email to us, we accepts the email but DO NOT send a ticket reply. If client@gmail.com sends an email to us, we send a ticket opened reply.

I have made hooks before, I am just wondering which one to use in terms checking the incoming email during support ticket creation.

Link to comment
Share on other sites

19 hours ago, Kian said:

Hi,

Use EmailPreSend action hook to verify that the sender is a registered user. If he's not, abortsend true. Game over.

Great idea. However do you know how I get the email address? The documentation is a bit fuzzy. It gives a variable called $var, but what is the available items in that? As this is a hook, I have no way to output the value of $var.

Edited by craigedmonds
Link to comment
Share on other sites

21 minutes ago, craigedmonds said:

Great idea. However do you know how I get the email address? The documentation is a bit fuzzy. It gives a variable called $var, but what is the available items in that? As this is a hook, I have no way to output the value of $var.

Actually I figured it out.

I Added a line into the hook like below and the log gave me all the variable names, then I open the log file and shows all the fields in $var.
 

if ($vars['messagename'] == 'Support Ticket Opened') {
		$root = realpath($_SERVER["DOCUMENT_ROOT"]);
		error_log(print_r($vars, true), 3, $root.'/WHMCS-ERROR-LOG.log');
}

The variable for the senders email will be:
 

$vars['mergefields']['client_email'];

 

Edited by craigedmonds
Link to comment
Share on other sites

My Final Code.
 

if ($vars['messagename'] == 'Support Ticket Opened') {

   //get the from address
   $from = $vars['mergefields']['client_email'];

   //set the score
   $score = 0;
		
   //check inside of tblclients if $from exists
   $result = full_query("SELECT email FROM tblclients WHERE email = '$from'");
   $rows = mysql_num_rows($result);
   if ($rows == 0) { $score = $score + 1; }

   //check inside of tblcontacts if $from exists
   $result = full_query("SELECT email FROM tblcontacts WHERE email = '$from'");
   $rows = mysql_num_rows($result);
   if ($rows == 0) { $score = $score + 1; }

   //abort or not
   if($score == 2) {
     $return['abortsend'] = true; 
   }
		
}

 

Edited by craigedmonds
Link to comment
Share on other sites

I would change it like follows:

if ($vars['messagename'] == 'Support Ticket Opened') {

   //get the from address
   $from = $vars['mergefields']['client_email'];
	
   //check inside of tblclients if $from exists
   $result = full_query("SELECT email FROM tblclients WHERE email = '$from' LIMIT 1");
   $rows = mysql_num_rows($result);
   $AbortSend = ($rows ? false : true);

   //check inside of tblcontacts if $from exists
   if (!$AbortSend)
   {
      $result = full_query("SELECT email FROM tblcontacts WHERE email = '$from' LIMIT 1");
      $rows = mysql_num_rows($result);
      $AbortSend = ($rows ? false : true);
   }

   if ($AbortSend): $return['abortsend'] = true; endif;
}
  • I added LIMIT 1 to both of your queries since you are looking for first match. There's no need to keep iterating through the entire table
  • Your "score" thing doesn't work since you are aborting the send only when the email exists in both tblclients and tblcontacts which is impossible
  • There's no need to check for the email in tblcontacts when you have already found it in tblclients
Link to comment
Share on other sites

25 minutes ago, Kian said:

I would change it like follows:

  • I added LIMIT 1 to both of your queries since you are looking for first match. There's no need to keep iterating through the entire table
  • Your "score" thing doesn't work since you are aborting the send only when the email exists in both tblclients and tblcontacts which is impossible
  • There's no need to check for the email in tblcontacts when you have already found it in tblclients

Nice suggestions thanks, especially the LIMIT 1 that makes pure sense.

As for the score, actually that does work, because when the query starts,  the score is 0, then if the email is not found in tblclients the score is increased to 1, then we check the tblcontacts and if its not found there either, the score is increased to 2. If the score = 2 then we abort sending otherwise we send (I did test this with two different email accounts, one a registered client and the other not, and worked great).

Sure, I could avoid checking the tblcontacts if the email is found in tblclients but for  the sake of easier to read  code and the fact it's a basic select query I just quickly checked it anyway, does no harm. I could have actually used a union query to check both tables at the same time I guess and that would have made the code shorter but for the sake of what I am doing today, it works.

Thanks for your input, very grateful.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated