Jump to content

Hook for TicketOpen and specific support department ID


sol2010

Recommended Posts

Hi

 

I would like to send an email to another address if a ticket is opened from a specific support department ID. Here is my hook, but it's not working. Advice please;

 


<?php

if (!defined("WHMCS"))
   die("This file cannot be accessed directly");

function hook_send_emergency_email($vars) {

 $criticaldept = 5; // id of emergency department from whmcs admin

 $deptid = $vars['deptid'];
 $company = $vars['companyname'];

if (in_array($vars['deptid'], $criticaldept)) {


  // Send email to specified address
       $to = 'example@gmail.com';

       // e-mail subject
       $subject = "Emergency Ticket Alert";

       // e-mail message
       $message = "Hello Admin,\r\n"
       ."Emergency Ticket Opened For:\r\n"
       ."Company: $company\r\n";

       $headers = "From: Some Company <support@somecompanyemailaddy.com>\n"
       ."Reply-To: support@somecompanyemailaddy.com\n"
       ."X-Mailer: PHP/".phpversion();

       mail( $to, $subject, $message, $headers );       

       }  // if in_array

}

add_hook("TicketOpen",1,"hook_send_emergency_email");



Link to comment
Share on other sites

  • WHMCS Developer

You can use the function logActivity to check and ensure your hook is running as you expect.

 

For example:

 

logActivity("Department is {$vars['deptid']}");

 

You can then check the activity log to see where in your hook the system is getting.

 

Finally, you should check to ensure that your mail() function call is returning true/false.

 

If your mail is going to an admin set of email addresses, you could also use the WHMCS SendAdminEmail API command as this will allow you to use the WHMCS Activity Log to ensure your mail is being sent correctly - http://developers.whmcs.com/api-reference/sendadminemail/

 

The internal api is available when a hook runs

Link to comment
Share on other sites

  • 1 month later...

Thanks - I will look into that.  Is there any more detail on how to use the function logActivity ? Where would I add that in my code.

Could you advise if the code for the hook is in theory, correctly written ?

Thanks

 

Edited by sol2010
Link to comment
Share on other sites

Regarding the  logActivity,
 you can call just after

if (in_array($vars['deptid'], $criticaldept)) {

To make sure that your email sending code is executing or not.

 

Also make sure that email function is working properly in your server.

You can just create a simple php file, and run from it.

 

<?php
// The message
$message "my message";
// Send
mail('me@mydomain.com''My Subject'$message);

?>
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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