I have created a script which pulls results out of a database of emails to be sent. If the current time is greater than or equal to the time the message was set to be sent the message sends.
My problem is that the script does not send every message if there is more than one set to run. It will send the first and send the second the next time it runs, the third the next time, etc...
This script is set to run every 5 minutes via a cron job.
<?
include('includes/connect.inc');
// Check/Run Reminders
$result = mysql_db_query($database, "SELECT * FROM reminders");
$rcount = mysql_num_rows($result);
$i=0;
do{
while ($row = mysql_fetch_array($result)){
$id = $row['id'];
$timestamp = $row['timestamp'];
$msg = $row['message'];
$number = $row['destination'];
$carrier = $row['carrier'];
if(gmmktime() >= $timestamp){
mail($number . "@" . $carrier, "SMS", $msg, "From: [email]sms@webc0der.net[/email]\r\n");
$result = mysql_db_query($database, "DELETE FROM reminders WHERE id=\"$id\"");
}
}
$i++;
}while($i<$rcount);
?>