I worked on the code based on http://www.daniweb.com/web-development/php/threads/123389
but as per last answer to use the mail function outside loop ( http://www.daniweb.com/web-development/php/threads/123389/708835#post708835), I still cant work with this script. Please help
<?
$query="SELECT * FROM tbl_users WHERE ex_date between now() and adddate(now(), INTERVAL 7 DAY) ORDER BY user_id ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
?>
<?php
$i=0;
while ($i < $num)
{
$id=mysql_result($result,$i,"user_id");
$email=mysql_result($result,$i,"login_email");
$loginname=mysql_result($result,$i,"loginname");
$ex_date=mysql_result($result,$i,"ex_date");
$ex_date = date("d-m-Y", strtotime($ex_date) );
?>
<?php
$i++;
}
?>
<?
if($query == TRUE)
{
//send email
$to = "$email";
$subject = "Expriy Notice";
$from = "Admin";
$msg .= "Hello $loginname,<BR><BR>";
$msg .= "Your Account will expire in 7 days. Your Expiry Date is $ex_date<BR><BR>";
$msg .= "Regards: <BR><BR>Admin";
$msg .= "Admin";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: Admin\r\nReply-To:sammy@gmail.com" . "\r\n";
$mailsend = mail("$to","$subject","$msg","$headers");
echo $mailsend ? "Email was sent :-)." : " Email sending failed.";
}
?>
What am i doing wrong?