MySQL results in email


/ Published in: PHP
Save to your folder(s)

Take the contens from a table in MySQL and display it in an email


Copy this code and paste it in your HTML
  1. function message()
  2. {
  3. $m2 = '';
  4. $result = mysql_query("SELECT * FROM inventory WHERE count < 4");
  5. while($row = mysql_fetch_array($result))
  6. {
  7.  
  8. $m2 .= $row['item']. ": " .$row['count'] . "<br>";
  9. }
  10. return $m2;
  11. }
  12.  
  13.  
  14.  
  15. $subject = "My subject";
  16.  
  17.  
  18. $headers = "MIME-Version: 1.0" . "
  19. ";
  20. $headers .= "Content-type:text/html;charset=iso-8859-1" . "
  21. ";
  22.  
  23. $headers .= "From: $from";
  24. $message = message();
  25. mail($to,$subject,$message,$headers);
  26. echo "Mail Sent.";

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.