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 = '[email protected]';

       // 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 <[email protected]>\n"
       ."Reply-To: [email protected]\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('[email protected]in.com''My Subject'$message);

?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • 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!
       
    • By Web Host Pro
      Hi,
      I am trying to add a link tot he affiliate login page under the account menu section. Just like the log in hook for the main section. I would like it to be under the:
      login
      register
      lost password
      (Affiliate Login)
      Thanks for any help. I've checked the TMSecondaryNavbar.php file but can't see what to add.
      I tried to add this: 
      $primaryNavbar->getChild('Company')
                          ->addChild('Affiliate Login', array(
                          'uri' => 'affiliates.php',
                          'order' => '20',
                      ));
      But it crashed the whole site.
      Thank you,
      Charles
    • By v1ktor
      Ok, so I have a hook in place for ShoppingCartCheckoutCompletePage. When they reach completion page, hook checks for products in the order and based on product ID and if order status is pending, it sends out a correct email. Because I'm using ShoppingCartCheckoutCompletePage hook, the email should go out right there and then when order is complete.
       
      So why does the email go out when dailycron runs in the morning? Thoughts?
       
      I'm using internal API inside hook to sendmail with a correct template.
    • By bigideaguy
      Hey guys!
       
      I was unable to find a good way of updating bitcoin currency rates so I decided to create my own module to do this for me and that resultet in Anveto Currency Rates.
       

       
      This addon will update additional currency rates when the daily cron runs or when Anveto cron runs (see downloads here for anveto cron https://anveto.com/members/downloads/2/WHMCS) in order to update currencies multiple times daily. Currently it uses the bitpay (https://bitpay.com/api/rates) to get currency rates but you could set this to any source as long as it follows the same json format.
       
      The module costs $10 and can be purchased here https://anveto.com/members/cart.php?a=add&pid=21
       
      It is currently pending community app store review.
       
      The source code is not encrypted as I want users to be able to modify this however they would like as long as they purchase the module.
       
      I hope some of you find it useful!
    • By willk
      Hi All,
       
      In the hook hook_system_emailpresend is it possible to change the From email and From name.
       
      Thanks,
      Will
  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

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