affordit Posted January 25, 2008 Share Posted January 25, 2008 I am tring to use the code below to loop thru my table and send mail to all addresses where subscription is about to expire. I get no errors but mail does not send. <?php $ds = date("Y-m-d",strtotime("+8 days")); include("sharons_dbinfo.inc.php"); mysql_connect(mysql,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "select field3 from test WHERE field4 = '$ds'"; $result=mysql_query($query) or die (mysql_error()); if (($result)||(mysql_errno == 0)) { if (mysql_num_rows($result)>0) { $i = 0; while ($i < mysql_num_fields($result)) { $i++; } //display the data while ($rows = mysql_fetch_array($result,MYSQL_ASSOC)) { echo "<br>"; foreach ($rows as $data) { $to = "$data"; $subject = "Your Subscription"; $message="Your subscription will expire in seven days." $headers = "From: [email protected]"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } } } }else{ echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>"; } echo "</table>"; }else{ echo "Error in running query :". mysql_error(); } ?> Link to comment https://forums.phpfreaks.com/topic/87789-solved-help-with-sending-mail/ Share on other sites More sharing options...
affordit Posted January 25, 2008 Author Share Posted January 25, 2008 Nevermind I found it Link to comment https://forums.phpfreaks.com/topic/87789-solved-help-with-sending-mail/#findComment-449100 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.