mearls Posted July 21, 2011 Share Posted July 21, 2011 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"); ?> 0 Quote Link to comment Share on other sites More sharing options...
WHMCS CEO Matt Posted July 22, 2011 WHMCS CEO Share Posted July 22, 2011 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 0 Quote Link to comment Share on other sites More sharing options...
alai Posted October 23, 2011 Share Posted October 23, 2011 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 Thanks!! 0 Quote Link to comment Share on other sites More sharing options...
alai Posted October 31, 2011 Share Posted October 31, 2011 Hi! I would like to do exactly the same, but after reading the documentation I haven't understand anything... Could you tell me a little explanation for non-knownledge people? Thank you very much!! Anyone could help me? 0 Quote Link to comment Share on other sites More sharing options...
mearls Posted July 12, 2012 Author Share Posted July 12, 2012 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(); ?> 0 Quote Link to comment Share on other sites More sharing options...
mearls Posted July 12, 2012 Author Share Posted July 12, 2012 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",""); */ ?> 0 Quote Link to comment Share on other sites More sharing options...
mearls Posted August 17, 2012 Author Share Posted August 17, 2012 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'); } } ?> 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.