How to get results from a while loop in to the body of email
Posted: Tue Feb 24, 2009 9:58 am
see my code
basically its for esculation on a helpdesk facility i have made. it needs to list the call ref number for the ones that over 14days old and send an email. problem is its only sending 1 result. i know why as the $message variable is getting overwritten by the loop each time it is looping but how can i stop this and allow it to list all results?
Code: Select all
<?php
include 'config.php';
include 'opendb.php';
$query = "SELECT id, username, subject, date, status, escalated FROM `helpdesk` WHERE `date` < CURDATE()-14 and status LIKE '%Open' and escalated is NULL";
$result = mysql_query($query) or die('Error : ' . mysql_error());
$numrows = 0;
$numrows = mysql_num_rows($result);
while (list($id, $username, $subject1, $date, $status, $escalated) = mysql_fetch_array($result, MYSQL_NUM)) {
$message = "$id";
};
$to = "me@me.com";
$subject = "Call Updates";
$email = "test@test.com";
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
include 'closedb.php';
?>