snake Posted July 12, 2017 Share Posted July 12, 2017 I have the following hook, but it is not working, no email is being sent, can anyone tell me why? <?php //hook to send notes to all dept staff rather than only to the person assigned to the ticket. if (!defined("WHMCS")) die("This file cannot be accessed directly"); function send_note_ticket($vars) { $ticketid = $vars['ticketid']; $message = $vars['message']; $adminid = $vars['adminid']; //Get department id $query = mysql_query("SELECT `did`,`tid` FROM `tbltickets` WHERE `id` = '$ticketid'"); $dep_data = mysql_fetch_assoc($query); $departmentid = $dep_data['did']; $tid = $dep_data['tid']; //send email notification $command = "sendadminemail"; $adminuser = "ADMINAPI";//change this if you change admin username $values = array(); $values["messagename"] = "Ticket Note Added"; $values["mergefields"] = array( "ticket_id" => $ticketid, "ticket_tid" => $tid, "ticket_message" => $message, ); $values["type"] = "support"; $values["deptid"] = $departmentid; $results = localAPI($command,$values,$adminuser); } add_hook("TicketAddNote",1,"send_note_ticket"); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 12, 2017 Share Posted July 12, 2017 from previous experience, I know the hook in the thread below works, so it might be worth adapting that for your needs. https://forum.whmcs.com/showthread.php?121486-Send-Email-on-Ticket-Note-(no-longer-working)&p=488886#post488886 0 Quote Link to comment Share on other sites More sharing options...
snake Posted July 18, 2017 Author Share Posted July 18, 2017 Thanks I had a look, I cannot reply to that thread since it is too old. This looks like it sends an email to ALL staff. Do you know, Is there any way to limit it to only send an email staff of the DEPT that the ticket is in, so that billing and sales not get an email about a SUPPORT ticket. This is what my hook did. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 18, 2017 Share Posted July 18, 2017 I was assuming you were just going to take your deptid query and replace the adminroles query from the other script. but if you say your hook code worked previously, then it might be worth outputting at each step to see where the issue lies... I assume there is an admin email template called "Ticket Note Added" ?? 0 Quote Link to comment Share on other sites More sharing options...
snake Posted July 18, 2017 Author Share Posted July 18, 2017 I was assuming you were just going to take your deptid query and replace the adminroles query from the other script. but if you say your hook code worked previously, then it might be worth outputting at each step to see where the issue lies... I assume there is an admin email template called "Ticket Note Added" ?? I did not write this hook myself, I am not a PHP developer. 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 24, 2017 Author Share Posted August 24, 2017 no developers here who can help with this ? 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 24, 2017 Author Share Posted August 24, 2017 nevermind, I have read the API docs and fixed it myself now, and added some extra functionality. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 24, 2017 Share Posted August 24, 2017 nevermind, I have read the API docs and fixed it myself now, and added some extra functionality. which, of course, you're going to share for others to use... 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 24, 2017 Author Share Posted August 24, 2017 which, of course, you're going to share for others to use... Well I was going to upload it to the marketplace, but it doesn;t seem to support hooks anymore, only modules. 0 Quote Link to comment Share on other sites More sharing options...
snake Posted August 24, 2017 Author Share Posted August 24, 2017 Below is my updated code. You need to create an email template, this really belongs under admin messages, which you cannot create via WHMCS, so you will need to do in via PHPMyAdmin if you want to put it there. subject: Note Added to ticket #{$ticket_tid} {$ticket_subject} content: {$sender} has added the following note to ticket ---------------------------------------------- Ticket ID: #{$ticket_tid} Subject: {$subject} Status: {$status} ---------------------------------------------- Note: {$ticket_message} <?php //hook to send notes to all dept staff rather than only to the person assigned to the ticket. if (!defined("WHMCS")) die("This file cannot be accessed directly"); function send_note_ticket($vars) { $ticketid = $vars['ticketid']; $message = $vars['message']; $adminid = $vars['adminid']; //Get department id $query = mysql_query("SELECT `did`,`tid`,`title`,`status` FROM `tbltickets` WHERE `id` = '$ticketid'"); $dep_data = mysql_fetch_assoc($query); $query = mysql_query("SELECT `firstname`,`lastname` FROM `tbladmins` WHERE `id` = '$adminid'"); $sender = mysql_fetch_assoc($query); $departmentid = $dep_data['did']; $tid = $dep_data['tid']; $subject = $dep_data['title']; $status = $dep_data['status']; //send email notification $command = "sendadminemail"; $adminuser = "ADMINAPI";//change this if you change admin username $values = array(); $values["messagename"] = "Ticket Note Added"; $values["mergefields"] = array( "ticket_id" => $ticketid, "ticket_tid" => $tid, "ticket_message" => $message, "subject" => $subject, "status" => $status, "sender" => $sender['firstname'] . " " . $sender['lastname'] ); $values["type"] = "support"; $values["deptid"] = $departmentid; $results = localAPI($command,$values,$adminuser); logModuleCall('API', 'SendAdminEmail', $values, $results); } add_hook("TicketAddNote",1,"send_note_ticket"); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 24, 2017 Share Posted August 24, 2017 You need to create an email template, this really belongs under admin messages, which you cannot create via WHMCS, so you will need to do in via PHPMyAdmin if you want to put it there. I suppose you could create it as a general message from within WHMCS, and then just edit the 'type' value in tblemailtemplates... you'd still need to do that in phpmyadmin (or similar), but might be slightly easier for those unfamiliar with interacting with the tables directly. 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.