I have set up a cron job to do email out meeting reminders for my customers, but it doesn't appear to be working. Yet, when I load the page manually, it works and echo's just fine. Can someone help?
My script that I'm trying to run is as shown below.
require('../../dbconfig.php');
$sql = " SELECT email, name, webinar_date FROM webinar_list";
$query = mysqli_query($conn, $sql);
while ($row=mysqli_fetch_assoc($query))
{
$email = $row['email'];
$name = $row['name'];
$webinarTime=$row['webinar_date'];
echo "current time = ".$currentTime=time(); echo "<br>";
echo "registered time = ".$registeredTime=strtotime($row['webinar_date']); echo "<br>";
echo "Difference = ".$timeDiff=$currentTime - $registeredTime;
//IF TIME DIFFERENCE IS <60 MIN BUT LESS THAN 55MIN
if(($timeDiff<=3600)&&($timeDiff>=3300))
{
$message = oneHour($name);
echo $message;
$from = "reminder@theleagueoffreedom.com";
$to = $email;
$subject = 'Just A Friendly Reminder...';
$headers = "From: Anthony Moto \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
mail($to,$subject,$message, $headers);
}
//IF TIME DIFFERENCE IS <10 MIN BUT GREATER THAN 5MIN
elseif(($timeDiff<=600)&&($timeDiff>=300))
{
$message = tenMinutes($name);
echo $message;
$from = "reminder@EXAMPLE.com";
$to = $email;
$subject = 'RE:10 Minutes...';
$headers = "From: Anthony Moto \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
mail($to,$subject,$message, $headers);
}
//IF TIME DIFFERENCE IS <5 MIN BUT LESS THAN -5MIN
elseif(($timeDiff<=300)&&($timeDiff>=-300))
{
$message = liveTraining($name);
echo $message;
$from = "reminder@EXAMPLE.com";
$to = $email;
$subject = 'We Are Starting NOW!';
$headers = "From: Anthony Moto \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
mail($to,$subject,$message, $headers);
}
}
I return $message variable in the functions I call which is a string of letters. My cron job looks like this.
*/10 * * * * /usr/local/bin/php -q /home/username/public_html/example.com/webinar_emails/p0/webinar_reminder.php
If it helps, the currentTime is taken from SQL and it is in this format:
2016-11-27 11:00:00
The issue that I'm having is that I don't get any emails at all. I've checked my spam folder as well. I don't even get a "blank" email. And like I said, the code echo's out the current time and time difference just fine. But the Cron doesn't appear to be running the script.
Any help would be appreciated and I will be forever grateful!
Thanks