Ok what i want is to go through database and send an email to every email whose database stored time and date is lower then current date and whose sent value is 0. Whats working is it goes through the loop of email and sends the emails however what i want to do is to set sent value in the database from 0 to 1 so that if i ran the program in the future it wont send the emails again to people that i already have send an email. i tried updating the send value to 1 inside my while loop but when i execute my file it stops after just one email, so it doesn't loop through database
<?php
include_once("db.php");
$date = new DateTime();
//echo $date->format('Y-m-d H:i:s')
$query = "SELECT timedate, email, sent, msgid FROM mailer";
$result = mysql_query($query);
echo "<table>";
while($row = mysql_fetch_array($result)){
$tot = $row['timedate'];
$ema = $row['email'];
$sendflag = $row['sent'];
$mess = $row['msgid'];
if(strtotime($tot) > time()) {
//echo "<tr><td>" .$row['timedate']."</td><td>";
echo"database dates higher then now dates" . "<br>";
echo "<tr><td>" .$row['email']."</td><td>" ."<br>";
echo "<tr><td>" .$row['timedate']."</td><td>" ."<br>";
echo "<tr><td>" .$row['sent']."</td><td>" ."<br>";
}
else {
echo"database dates lower then now dates" . "<br>";
echo "<tr><td>" .$row['email']."</td><td>". "<br>";
echo "<tr><td>" .$row['timedate']."</td><td>" ."<br>";
echo "<tr><td>" .$row['sent']."</td><td>" ."<br>";
$subject = "This is subject";
$message = "This is simple text message.";
$header = "From:abc@somedomain.com \r\n";
$to = $row['email'];
$retval = mail ($to,$subject,$message,$header);
if( $retval == true )
{
echo "Message sent successfully..." ."<br>";
}
else
{
echo "Message could not be sent..." ."<br>";
}
//$sql = "UPDATE mailer SET sent = 1 WHERE msgid = $mess";
$query = "UPDATE mailer SET sent = 1 WHERE msgid = $mess";
$result = mysql_query($query);
}
}
mysql_close();
?>