Jump to content
Sign in to follow this  
sol2010

Hook for TicketOpen and specific support department ID

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");



Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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);

?>

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Similar Content

    • By Lightfaro
      Hi everybody!
      I need to delete or hide some links from the sidebar into the client area, as in attachment
      As they told me from the support I must do it using hooks, but I really don't know how to start
      Any help you can give me will be welcome. 😄
      Thanks!! 

    • By katyaweb
      Hello, 
       
      I have written a custom logic using hook AfterModuleSuspend. 
      WHMCS calling this hook method when I am suspending a hosting account manually from admin area. But, its not calling while daily cron suspending a hosting account.
      Is this expected ?
       
    • By WHMCS Danny
      Hi Friends,
      I have found some users that may need to add certain HTML code for many different reasons to the client area of WHMCS. This could be for tracking code, Google tag manager or a custom Live chat addon that you need to ensure their custom HTML code is added to a  certain section on the page via HTML or JS code per the instructions of what you are adding to the client area pages.
      The best way to achieve this would to use a custom hook. Depending on where you need to place your HTML code on the page, you would use one of the below hooks:
      If you want to add HTML code to be placed in the <head> section of the page your would use the ClientAreaHeadOutput hook. If you want  to add HTML code to be placed in the <body> section of the page you would use the ClientAreaHeaderOutput  hook. If you want to add HTML code to be placed in the <footer> section of the page you would use the ClientAreaFooterOutput hook This assumes you are already familiar with creating hooks. For further information to learn how to create hooks please review the following developers documentation:
      https://developers.whmcs.com/hooks/getting-started/
      Once your hook is saved under your /includes/hooks/ directory in your WHMCS installation, you can use the use your browsers developer tools to Inspect the client area pages to check that your code has be inserted where it needs to be placed or where you wanted it to be placed on the page.

      Instructions: I have provided example snippets below for creating a hook for each section to add HTML code to the client area pages for the <head>, <body> or <footer> sections of the client area pages after the PHP has been rendered.

      All you will need to do is insert your HTML code in between the <!-- Start insert code here -->  and <!-- End insert code here --> comments in the below examples.

      ClientAreaHeadOutput Hook Example: The code you place in between the comments referenced above will add your HTML code to the <head> section of every client area page:
      <?php /** * The code below will be added in the <head> section * @author WHMCS Danny */ add_hook('ClientAreaHeadOutput', 1, function($vars) { return <<<HTML <!-- Start insert code here --> <!-- End insert code here --> HTML; });
      Source: https://developers.whmcs.com/hooks-reference/output/#clientareaheadoutput

      ClientAreaHeaderOutput  Hook Example: The code you place in between the comments referenced above will add your HTML code to the <body> section of every client area page:
      <?php /** * The code below will be added in the <body> tag section * @author WHMCS Danny */ add_hook('ClientAreaHeaderOutput', 1, function($vars) { return <<<HTML <!-- Start insert code here --> <!-- End insert code here --> HTML; });

      Source: https://developers.whmcs.com/hooks-reference/output/#clientareaheaderoutput

      ClientAreaFooterOutput Hook Example: The code you place in between the comments referenced above will add your HTML code to the <footer> section of every client area page:
       
      <? /** * The code below will be added to the <footer> tag section * @author WHMCS Danny */ add_hook('ClientAreaFooterOutput', 1, function($vars) { return <<<HTML <!-- Start insert code here --> <!-- End insert code here --> HTML; });
      Source: https://developers.whmcs.com/hooks-reference/output/#clientareafooteroutput

      I hope this information helps anyone who is looking on how to add HTML/JS code to your WHMCS client area, such as, a tracking code, Google tag manager or a custom Live Chat addon etc.
       
      Best Regards,
      -  WHMCS Danny
    • By dewdropz
      Can you make a hook for a specific service terminated day? Or any module available for it? For example, I am selling business email and hosting both. But for business email, termination day needs 3 days but hosting need 1month/30 days. But for whmcs default system, only 1 day I can select.
    • By trolling
      Hi, I'm writing this post in order to know if is it possible to do an action, when loading the page, using a module or a for example ? 
      Thank you for your help.
  • 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