0

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

4
  • 1
    Maybe the CRON user doesn't have permissions to execute that script? You can log the output of the script by appending a > and a location after the script name. stackoverflow.com/questions/4811738/cron-job-log-how-to-log
    – chris85
    Nov 27, 2016 at 18:47
  • 1
    when you run this /usr/local/bin/php -q /home/username/public_html/example.com/webinar_emails/p0/webinar_reminder.php from the command window do you have any output or any error message ?
    – Faisal
    Nov 27, 2016 at 18:56
  • 1
    besides cron possibly not having needed permissions you also need to consider cron has little to no environment variables.. Things like $PATH that a standard user has to easily access common commands do not exist for cron, so you usually need to use entire file path, like require('/home/username/public_html/example.com/dbconfig.php'); Nov 27, 2016 at 19:00
  • I am using godaddy servers. Is there a way to check the output on godaddy?
    – Anthony Vu
    Nov 27, 2016 at 19:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.