spfoonnewb Posted January 12, 2007 Share Posted January 12, 2007 Hi, I am trying to email a database... via PHP.. this is the error:Warning: mail() expects parameter 3 to be string, resource given in /home/me/www/email.php on line 15Message delivery failed...[code]<?php$to = "[email protected]";$subject = "Name List";$link = mysql_connect("localhost", "username", "password") or die(mysql_error());mysql_select_db("database") or die(mysql_error());$sql = mysql_query("SELECT * FROM `test`") or die(mysql_error()); mysql_close ($link);$body = $sql;if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); }?>[/code] Link to comment https://forums.phpfreaks.com/topic/33841-email-a-database/ Share on other sites More sharing options...
.josh Posted January 12, 2007 Share Posted January 12, 2007 you may want to work on formatting the results, but...[code]<?php$to = "[email protected]";$subject = "Name List";$link = mysql_connect("localhost", "username", "password") or die(mysql_error());mysql_select_db("database") or die(mysql_error());$sql = mysql_query("SELECT * FROM `test`") or die(mysql_error()); $info = "<table>";while($list = mysql_fetch_assoc($sql)) { $info .= "<tr>"; foreach($list as $val) { $info .= "<td>$val</td>"; } $info .= "</tr>";}$info .="</table>";mysql_close ($link);$body = $info;if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); }?>[/code] Link to comment https://forums.phpfreaks.com/topic/33841-email-a-database/#findComment-158788 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.