Jump to content

Action Hook to send survey email on ticket close


mearls

Recommended Posts

Hi All,

 

I am trying to build an action hook that would search SQL, based on todays date and look for closed tickets, then send out a survey email from the email templates. Any thoughts or suggestions.

 

Thanks,

Michael

 

 

<?php
function customerSurveyClose($vars) {

       $results = mysql_query("SELECT *  FROM `tbltickets` WHERE `date` LIKE '".date(Y-m-d)."%' and status = 'Closed'");
                       $data = mysql_fetch_array($results);
                       $tid = $data['tid'];
                       $email = $data['email'];

}

add_hook(TicketOpen,1,"customerSurveyClose");

function sendEmailSurvey($vars) {  
$email_template_name = $vars['Customer Support Satisfaction Survey']; # Email template name being sent
  $tid = $vars['tid']; # Related ID it's being sent for - client ID, invoice ID, etc...    
  $email = $vars['email']; # Related ID it's being sent for - client ID, invoice ID, etc...
  if ($x='y') $merge_fields['abortsend'] = true; # You can use this return to stop email sending

}
add_hook("EmailPreSend",1,"sendEmailSurvey");  
?>

Link to comment
Share on other sites

  • WHMCS CEO

You would probably be best off using the DailyCronJob hook point for this. That way the code would run once per day and you could select all tickets closed on the previous day (ie. where last reply = day before and status=Closed) then use the Internal API to send the "Customer Support Satisfaction Survey" email template you've created in Setup > Email Templates via the "SendEmail" API function.

 

http://docs.whmcs.com/Hooks:Misc#DailyCronJob

http://docs.whmcs.com/API:Internal_API

 

Hope this helps.

 

Matt

Link to comment
Share on other sites

  • 3 months later...
You would probably be best off using the DailyCronJob hook point for this. That way the code would run once per day and you could select all tickets closed on the previous day (ie. where last reply = day before and status=Closed) then use the Internal API to send the "Customer Support Satisfaction Survey" email template you've created in Setup > Email Templates via the "SendEmail" API function.

 

http://docs.whmcs.com/Hooks:Misc#DailyCronJob

http://docs.whmcs.com/API:Internal_API

 

Hope this helps.

 

Matt

 

Hi Matt

 

Do you have a tutorial step-by-step? I would like to do the same thing as mearls, but I have no idea about php :lol:

 

Thanks!!

Link to comment
Share on other sites

  • 8 months later...

Matt or Team,

 

Would this work based on the above example?

 


<?php


function customerSurveyClose($vars) { 

       $results = mysql_query("SELECT *  FROM `tbltickets` WHERE `lastreply` LIKE '".date('Y-m-d ', strtotime('-1 days'))."%' 
               and status = 'Closed'");
                  $data = mysql_fetch_array($results);     
                  $tid = $data['tid'];     
                  $email = $data['email'];     

}

function sendEmailSurvey($vars) { 
$email_template_name = $vars['Customer Support Satisfaction Survey']; # Email template name being sent 
  $tid = $vars['tid']; # Related ID it's being sent for - client ID, invoice ID, etc... 
  $email = $vars['email']; # Related ID it's being sent for - client ID, invoice ID, etc... 
  if ($x='y') $merge_fields['abortsend'] = true; # You can use this return to stop email sending 

}
add_hook("EmailPreSend",1,"sendEmailSurvey"); 

function DailyCronJob();

?>

Link to comment
Share on other sites

I have created this new action hook but everytime I uncomment out the script, whmcs will not load. Any suggestions?

 

<?php
/* 

function customerSurveyClose($vars) {
$results = mysql_query("SELECT *  FROM `tbltickets` WHERE `lastreply` LIKE '".date('Y-m-d ', strtotime('-1 days'))."%' and status = 'Closed'");
       $data = mysql_fetch_array($results);
       $tid = $data['tid'];
       $email = $data['email'];
       sendMessage(Customer Support Satisfaction Survey,194);
   }

add_hook("DailyCronJob",1,"customerSurveyClose","");
*/

?>

Link to comment
Share on other sites

  • 1 month later...

Can someone confirm this is a correct way of coding the email sent function, also if the message was sent successfully would it show up as a sent email within the syslog log or syslog email log?

 

<?php

add_hook("DailyCronJob",0,"checkClosedTACCases");
function hook_sendSurvey($vars) {
       $email_template_name = $vars['Customer Support Satisfaction Survey'];
       $relid = $vars['194'];

  $merge_fields = array();
  $merge_fields['$client_email'] = "client_email";

  if ($x=='y') $merge_fields['abortsend'] = true; 

  return $merge_fields;
}

function checkClosedTACCases($vars) {
       $results = mysql_query("SELECT *  FROM `tbltickets` WHERE `lastreply` LIKE '".date('Y-m-d ', strtotime('-1 days'))."%' and status = 'Closed'");
       $data = mysql_fetch_array($results);
       $email = $data[email];
               error_log($email,3,'hook_log');

       if (isset($email)) {
               add_hook("EmailPreSend",1,"hook_sendSurvey");
               error_log("Message was sent",3,'hook_log');
       }
       else {
               error_log("Message was not sent",3,'hook_log');
       }
}

?>

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