Hi Guys!
I am trying to come up with a simple script that will do the following:
1) Look into a database and run the following query
SELECT recip_email FROM recipients WHERE timestamp > DATE_SUB(NOW(), INTERVAL 3 DAY)
2) Then, take the results and send an email using something like
mail($to, $subject, $message, $headers);
The trouble is...I'm not sure how to setup the script. I have tried this approach:
<?
require('dbconfig.php');
$query ="SELECT * FROM recipients WHERE timestamp > DATE_SUB(NOW(), INTERVAL 3 DAY)";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
$headers = "From: ME <ME@mdomain.com>\r\n";
$subject = "This is test";
$message = "with this I test ";
mail($row[recip_email], $subject, $message, $headers);
}
?>
The above code works....however the problem is with my query. If the email addresses excisits more than once (which can happen) they get two emails. How can I re-structure the query so that it ignores email addresses so that the email address is only in the results one time and the others are ignored?