Jump to content

Email a database.


spfoonnewb

Recommended Posts

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 15

Message 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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.