craigedmonds Posted October 1, 2019 Share Posted October 1, 2019 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. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted October 1, 2019 Share Posted October 1, 2019 Hi, Use EmailPreSend action hook to verify that the sender is a registered user. If he's not, abortsend true. Game over. 1 Quote Link to comment Share on other sites More sharing options...
craigedmonds Posted October 2, 2019 Author Share Posted October 2, 2019 (edited) 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 October 2, 2019 by craigedmonds 0 Quote Link to comment Share on other sites More sharing options...
craigedmonds Posted October 2, 2019 Author Share Posted October 2, 2019 (edited) 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 October 2, 2019 by craigedmonds 0 Quote Link to comment Share on other sites More sharing options...
craigedmonds Posted October 2, 2019 Author Share Posted October 2, 2019 (edited) 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 October 2, 2019 by craigedmonds 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted October 2, 2019 Share Posted October 2, 2019 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 0 Quote Link to comment Share on other sites More sharing options...
craigedmonds Posted October 2, 2019 Author Share Posted October 2, 2019 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. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.