Form which updates MySQL DB, then sends email notification
Posted: Wed Sep 19, 2007 10:59 am
Hello,
I have a form which allows members of my team to update a particular table, upon updating I have php set to send an email to a certain address. What I'd like to include in this email is the table after it's been updated.
Here's what I'm currently using which isn't working:
Any ideas on how this can be done??
Thanks!
I have a form which allows members of my team to update a particular table, upon updating I have php set to send an email to a certain address. What I'd like to include in this email is the table after it's been updated.
Here's what I'm currently using which isn't working:
Code: Select all
<?php
$to = "user@domain.com";
$bcc = "user@domain.com";
$from = "user@domain.com";
$subject = "Subject";
$mail_body =
// DB Connection
$link = mysql_connect('localhost', 'username', 'password')
or die('Could not connect: ' . mysql_error());
mysql_select_db('dbname') or die('Could not select database');
// SQL Query
$query = 'SELECT * FROM dbtable';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$mail_body = "<table>";
$res = mysql_query("SELECT service, CurrentStatus FROM status");
while($res2 = mysql_fetch_array($res) )
{
$mail_body .= "<tr>";
foreach($res2 as $value)
{
$mail_body .= "<td> $value </tr>";
}
$mail_body .= "</tr>";
}
$mail_body .= "</table>";
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$to = "$to";
mail($to, $bcc, $subject, $message, $headers);
header("Refresh: 5; url=");
?>Thanks!