IrOnMaSk Posted July 8, 2011 Share Posted July 8, 2011 Hey 1221, I tested this code and it sent out to emails in database with specific info in the body of the email. I'm sorry I can't test your exact given info because i'm limited to only a certain outgoing mail servers. However, the code exact same. So here it is: <?php mysql_connect('localhost', 'root', '******') or die('could not connect: ' . mysql_error()); mysql_select_db("database") or die('cannot select the database'); ?> <html> <head> <title>create student table</title> <body> <?php $to = "'; $subject = 'email testing'; $message = "'; $message .= "<table border = 1>"; $message .= "<tr><th>Name</th><th>Email</th></tr>"; $query = "select Name, Email from info"; // adjust to your code $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)){ $message .= "<tr><td>"; $message .= $row['Name']; $message .= "</td><td>"; $to .= $row['Email']; $message .= $row['Email'] . "<br />"; $message .= "</table>"; //end email here // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers $headers .= 'From: <me@whatever.com>' . "\r\n";//i'm using my real address here to test $headers .= 'Cc: myboss@example.com' . "\r\n"; mail($to,$subject,$message,$headers); } ?> </body> </html> It works perfectly for me... make sure the addresses in the database are valid and enable the mailing port in php.ini If that's doesn't work for you, screw it lol Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 8, 2011 Share Posted July 8, 2011 try using CONCAT in your select $sql="SELECT CONCAT(PrimaryContact,email,hostname) FROM sm_table WHERE hostname='$hostname' ORDER BY hostname ASC "; should output something like zzz example@yahoo.com joe smith Quote Link to comment 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.