Jump to content

Hook stopped working


Recommended Posts

We use a hook to send a list of all invoices to our accountant each month.
It should run on the DailyCronJob and only run the script on the 30th of each month.
This no longer works.

When I change 'DailyCronJob' to 'AdminLogin' and I login to WHMCS it works like a charm.
What can be wrong?
The daily cron runs fine.
The cron runs from outside the webdirectory, but it always have done that, could that be of influence?

<?php

add_hook('DailyCronJob', 1, function ($vars)
{

 

Link to comment
Share on other sites

Thank you Kian,
It indeed says this, but then immediatly after that:

 

Error: Whoops\Exception\ErrorException: Cannot declare class phpmailerException, because the name is already in use in /home/sitename/public_html/clients/includes/class.phpmailer.php:2317 Stack trace: #0 /home/sitename/public_html/clients/vendor/whmcs/whmcs-foundation/lib/Utility/Error/Run.php(0): WHMCS\Utility\Error\Run->handleError(64, 'Cannot declare ...', '/home/sitename/p...', 2317) #1 [internal function]: WHMCS\Utility\Error\Run->handleShutdown() #2 {main}

 

I tried and google it but that did not return much, hope someone has an idea?

Link to comment
Share on other sites

  • WHMCS Staff

Hi @erwin123,

Typically, this error indicates that a customisation in your WHMCS installation (A custom hook or addon) is including a copy of PHPMailer, causing it to try and "declare" an exception twice.

I'd recommend reviewing all customisations to ensure that none are either including their own copy of PHPMailer or including a PHPMailer specific file as WHMCS autoloads PHPMailer already.

Link to comment
Share on other sites

Thanks both,

I did not write the script and am not a coder, but how does that makes sense if the script works fine when I change 'DailyCronJob' to 'AdminLogin'?
The mail in that case is being send without problems.

In the script I do find: require_once($base."/../class.phpmailer.php");
Should I # this entry out?
 

Link to comment
Share on other sites

Hook points based on Cron events are "special". Due to some technical reasons (path, automaker, user-agent...) a script that perfectly works on AdminLogin doesn't automatically mean that it will work for hooks that trigger with Cron Jobs.

The problem should be in your hook. Don't edit phpmailer class! 😦

Edited by Kian
Link to comment
Share on other sites

Thank you Kian,

Its a bit shooting in the dark as I'm no coder but could this be the culprit?
 

$mail = new PHPMailer();
		$mail->From = $CONFIG["SystemEmailsFromEmail"];
		$mail->FromName = $CONFIG["SystemEmailsFromName"];
		$mail->Subject = $subject;

 

Other mail related entries:

		$date_m = date("Y-m",strtotime("-2 week"));
		$sub = "CRM System";
		$accountant_email = "accountant@company-x.net";

$mail->MsgHTML($message);
$mail->AddAddress($accountant_email);
$mail->AddAddress("myown@email.com"); #testing purposes

 

Link to comment
Share on other sites

  • WHMCS Staff
2 hours ago, erwin123 said:

In the script I do find: require_once($base."/../class.phpmailer.php");
Should I # this entry out?
 

This is near-definitely the issue here.

As a hook, PHPMailer (and that file) is already included (or should be!)

You should also use the SendEmail API, rather than PHPMailer directly.

# that out and let us know if the issue persists.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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