I want to send email at a certain time with PHP, I setup a CronJob to run a script every 5 minutes but is something wrong with it. It sends a mail every 5 minutes or don't send at all. This is the script: <?php require("config.inc.php"); require("class/Database.class.php"); $db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE); $now = time(); $db->connect(); $sql = "SELECT * FROM remindere"; $rows = $db->fetch_all_array($sql); // print out array later on when we need the info on the page foreach($rows as $r){ if($now => $r['time']) { $to = $r['email']; $subject = 'Reminder'; $message = $r['titlu']; $headers = 'From: RemindeMe@gmail.com' . "\r\n" . 'Reply-To: fo.translator@gmail.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); deleteReminder($r['id']); } else {} } $db->close(); In my db i have this fields: ID: .. MAIL: the email to send the mail TIME: a php timestamp with the time when to send the email TITLU: the message to send in the email the deleteReminder() functions is supossed to delete the reminder if that was send. I think the problem is my condition from the if statement if($now => $r['time']). Thank you and sory for my English.
How many records are in the database? perhaps the script times out? Make a limit to run through X amount of rows.
For the beggining : Have you tested the script to see if it works as it should ? (By running it ) . You first need to determine what's your problem, the script or the cron . Now i've seen this piece of code : if($now => $r['time']) Code (markup): this should be : if($now >= $r['time']) Code (markup): You should take a look at php operators.
Cron is working how it should. The problem is my script. I tested it but it doesn't work ... any ideas?
$sql = "SELECT * FROM remindere"; What is the table name? I think it's `reminder`, right? and this line: $message = $r['titlu']; it's 'title'??