dannybrazil Posted March 8, 2011 Share Posted March 8, 2011 I have this sql: Code: $data = mysql_query("SELECT * FROM remind WHERE event_date = cast(now() as date) ") or die(mysql_error()); while($row = mysql_fetch_array($data)) { // ------ INFO FROM DATABASE FOR A SPECIFIC ENTRY -------- // $id=$row['id']; $day=$row['day']; $month=$row['month']; $email=$row['email']; $topic=$row['topic']; $text=$row['text']; // ======== check for DATE match - ONE DAY BEFORE =======// $message = "Hello,\n\n We would like to remind you that tomorrow: \n $text ___________________________________________________________________________________ *** PLEASE, DO NOT REPLY THIS MESSAGE *** ___________________________________________________________________________________ "; mail($email , "Reminder", $message, "From: \"E-main Reminder\" <reminder@reminder.com>\r\n" . "X-Mailer: PHP/" . phpversion()); }//enf od while loop I have ONE entry with this DATE...BUT it keeps looping It suppose to send only ONE e-mail isnt it ? any help ? Quote Link to comment https://forums.phpfreaks.com/topic/230030-sql-help/ Share on other sites More sharing options...
Pikachu2000 Posted March 8, 2011 Share Posted March 8, 2011 Because the mail() function is inside the while() loop, it will send one email for each result returned from the database. Also, rather than using date = CAST(NOW() AS DATE), you should be able to simply use date = CURDATE() . . . Quote Link to comment https://forums.phpfreaks.com/topic/230030-sql-help/#findComment-1184748 Share on other sites More sharing options...
dannybrazil Posted March 9, 2011 Author Share Posted March 9, 2011 Thanks. The thing is that I will have a table full of entries and I want that an EMAIL will be sent to each e-mail address on a specific date. And could be many entries on the same date. I was trying with ONLY one entry in the table, but it keeps looping. any way to send ONLY 1 e-mail to each e-mail address and then through it from the loop Quote Link to comment https://forums.phpfreaks.com/topic/230030-sql-help/#findComment-1184867 Share on other sites More sharing options...
jcbones Posted March 9, 2011 Share Posted March 9, 2011 Is event_date a DATE, TIMESTAMP, or DATETIME column? Quote Link to comment https://forums.phpfreaks.com/topic/230030-sql-help/#findComment-1184869 Share on other sites More sharing options...
dannybrazil Posted March 9, 2011 Author Share Posted March 9, 2011 DATE column Quote Link to comment https://forums.phpfreaks.com/topic/230030-sql-help/#findComment-1184967 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.