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: <[email protected]>' . "\r\n";//i'm using my real address here to test $headers .= 'Cc: [email protected]' . "\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 Link to comment https://forums.phpfreaks.com/topic/240806-sending-email-wtih-mysql-qurey-result-on-body/page/2/#findComment-1240269 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 [email protected] joe smith Link to comment https://forums.phpfreaks.com/topic/240806-sending-email-wtih-mysql-qurey-result-on-body/page/2/#findComment-1240277 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.