Jump to content
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.

  • Similar Content

    • By So, who am I ?
      Hello
       
      I use OrderDomainPricingOverride hook to change some domain price manually, I need two registrars to use this hook, but when I add hook file to the second registrar's folder I get blank page and the whole site shuts down.
       
      I don't use any registrar function in the file, I just check domain's sld and tld and generate price, how can I manage to use the hook for both registrars ?
      this is my whole hook file:
      <?php /** * WHMCS SDK Sample Registrar Module Hooks File * * Hooks allow you to tie into events that occur within the WHMCS application. * * This allows you to execute your own code in addition to, or sometimes even * instead of that which WHMCS executes by default. * * WHMCS recommends as good practice that all named hook functions are prefixed * with the keyword "hook", followed by your module name, followed by the action * of the hook function. This helps prevent naming conflicts with other addons * and modules. * * For every hook function you create, you must also register it with WHMCS. * There are two ways of registering hooks, both are demonstrated below. * * @see https://developers.whmcs.com/hooks/ * * @copyright Copyright (c) WHMCS Limited 2016 * @license https://www.whmcs.com/license/ WHMCS Eula */ // Require any libraries needed for the module to function. // require_once __DIR__ . '/path/to/library/loader.php'; // // Also, perform any initialization required by the service's library. /** * Register a hook with WHMCS. * * add_hook(string $hookPointName, int $priority, string|array|Closure $function) */ add_hook('AdminHomeWidgets', 1, function() { return new SampleRegistrarModuleWidget(); }); add_hook('OrderDomainPricingOverride', 1, function($vars) { // Perform operations to determine price // logActivity('OrderDomainPricingOverride 900', 0); $domain = explode('.', $vars['domain']); $sld = $domain[0]; $tld = '.' . $domain[1]; $domain_name = explode('.', $vars['domain']); if(count($domain_name)==2 && strlen($domain_name[0])==2 && $domain_name[1]=='ge'){ return 900.00; } }); /** * Sample Registrar Module Admin Dashboard Widget. * * @see https://developers.whmcs.com/addon-modules/admin-dashboard-widgets/ */ class SampleRegistrarModuleWidget extends \WHMCS\Module\AbstractWidget { protected $title = 'Sample Registrar Module'; protected $description = ''; protected $weight = 150; protected $columns = 1; protected $cache = false; protected $cacheExpiry = 120; protected $requiredPermission = ''; public function getData() { return array(); } public function generateOutput($data) { return <<<EOF <div class="widget-content-padded"> Your widget output goes here... </div> EOF; } }  
       
    • By servetas
      Hello All,
      I am trying to following part of code within the viewinvoice page but the paymentbutton is not updated. Is the smarty->assign option still supported?
      <?php function custom($vars) { global $smarty; if ($vars['filename'] == 'viewinvoice' && $vars['status'] == 'Unpaid') { $smarty->assign('paymentbutton', "BG"); } } add_hook('ClientAreaPage', 1, 'custom'); ?> The hook seems to run but the paymentbutton is not updated. Does anyone have the same issue? How can we update the paymentbutton?
    • By Charles Bradbeer
      Hello,
      I have built a hook to show a new navbar, but I want it to hide to not logged in members. Is this possible?
      Thank you
       
      My hook im using:
      <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)    {    $primaryNavbar->addChild('Tools')                ->setOrder(50);    $primaryNavbar->getChild('Tools')                ->addChild('Html Tester')                ->setUri('/html.php')                ->setOrder(1);    $primaryNavbar->getChild('Tools')                            ->addChild('Privacy Policy Generator')                ->setUri('/privacypolicygenerator.php')                ->setOrder(2);    $primaryNavbar->getChild('Tools')                            ->addChild('cPanel Backup Generator')                ->setUri('/backup.php')                ->setOrder(3); });  
    • By Web Host Pro
      I added a hook file to try and change the title tags on each domain per a thread here.
      I removed the bad hook called titles.php and the site is still down with this message: 
      Oops!
      Something went wrong and we couldn't process your request.
      Please go back to the previous page and try again.
      The template cache folder is empty and I've tried it from multiple locations and computers. I've rebooted apache and the server and no help.
      Once the bad hook file is gone how can it still crash the whole system. The site is Web Host Pro
      Any ideas how to fix it?
    • By UWH - David
      We are trying to include a productID into a tracking link so we can include the product which was purchased. A hook is required for it and we require someone who can write a simple one. 
      Example of the complete.tpl link:
      <img src="https://trackingurl.com/ep?ord={$ordernumber}&orderid={$orderid}&product={$THISISMISSING}&qlist={$smarty.session.orderdetails.Products|@count}&amtlist={$amount*100}&cur=USD&img=1">
      Thank you!
       
  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines