erwin123 Posted June 3, 2019 Share Posted June 3, 2019 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) { 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted June 3, 2019 Share Posted June 3, 2019 (edited) Utilities > Logs > Activity Log. Can you confirm that you have the following entry for 30th of previous month? Quote Cron Job: Completed Daily Automation Tasks Edited June 3, 2019 by Kian 2 Quote Link to comment Share on other sites More sharing options...
erwin123 Posted June 3, 2019 Author Share Posted June 3, 2019 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? 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted June 3, 2019 Share Posted June 3, 2019 Umh... you said that your hook sends an email and this error is about phpmailer class name already in use. There should be something wrong in how you are sending the email in the hook. 1 Quote Link to comment Share on other sites More sharing options...
WHMCS Staff WHMCS Peter Posted June 3, 2019 WHMCS Staff Share Posted June 3, 2019 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. 1 Quote Link to comment Share on other sites More sharing options...
erwin123 Posted June 3, 2019 Author Share Posted June 3, 2019 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? 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted June 3, 2019 Share Posted June 3, 2019 (edited) 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 June 3, 2019 by Kian 1 Quote Link to comment Share on other sites More sharing options...
erwin123 Posted June 3, 2019 Author Share Posted June 3, 2019 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 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted June 3, 2019 Share Posted June 3, 2019 Given that I can't determine if the code you posted is the responsible of the error, there should be an include() or require() right before new PHPMailer(). Try chagning them them to include_once() or require_once(). 1 Quote Link to comment Share on other sites More sharing options...
WHMCS Staff WHMCS Peter Posted June 3, 2019 WHMCS Staff Share Posted June 3, 2019 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. 0 Quote Link to comment Share on other sites More sharing options...
erwin123 Posted June 3, 2019 Author Share Posted June 3, 2019 @Kian Thank you, there's no include() or require() in the code, only require_once. @WHMCS Peter Thank you, I tried it and unfortunatly it won't work. The testscript with 'AdminLogin' stops with sending email if I # it out. So I guess the script needs it after all... 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.