I am experiencing an issue automating the sending of emails using PHPMailer and a cron job. I am using a shared hosting server and CPanel. I have tested my PHPmailer installation and have been able to successfully send a basic email by running the below script in the browser.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
/* Exception class. */
require '/home/eepherg/public_html/mobiq1.2/lib/PHPMailer-master/src/Exception.php';
/* The main PHPMailer class. */
require '/home/eepherg/public_html/mobiq1.2/lib/PHPMailer-master/src/PHPMailer.php';
/* SMTP class, needed if you want to use SMTP. */
require '/home/eepherg/public_html/mobiq1.2/lib/PHPMailer-master/src/SMTP.php';
/* Create a new PHPMailer object. Passing TRUE to the constructor enables exceptions. */
$mail = new PHPMailer(TRUE);
/* Set the mail sender. */
$mail->setFrom('darth@empire.com', 'Darth Vader');
/* Add a recipient. */
$mail->addAddress('test@provision.com', 'Emperor');
/* Set the subject. */
$mail->Subject = 'Force';
/* Set the mail message body. */
$mail->Body = 'There is a great disturbance in the Force.';
/* Finally send the mail. */
$mail->send();
?>
I have setup a CRON job as per the below to run once a day ...
12 00 * * * /usr/local/bin/php /home/eepherg/public_html/mobiq1.2/test.php
This CRON job runs without any errors, however no email is received. Is there perhaps an issue with my references or does anyone have any ideas why the script will work when run in the browser but not when run using the CRON job?