I am trying to send the results of a mysql query as a list in an email. If I use the same code to print the results using echo it works fine, but I cant Figure out how to send them in an email listing them the same as it does when using echo (showing results). Any Help would greatly be appreciated The Problem is that $services are not listed in the email. It shows one row of results only. NOTE: $services are in the middle of the message. Here is the code I have .
<?phprequire('../includes/invconfig.php');
$query = "SELECT * FROM inv_services WHERE invid = '$invid'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$invtype = $row[invtype];
$invdesc = $row[invdesc];
$invdomain = $row[invdomain];
$invcost = $row[invcost];
$i++;
$services = "$invtype $invdesc $invdomain $invcost";
}
$sendemail = "$_POST[emailaddress]";
$subject = "Invoice Number: $invnumb";
$fromName = "$sysemailfrom";
$fromAddress = "$sysemail";
$message = "Dear $bill_name,\n\nBelow Please Find Your Invoice # $invnumb That You Requested be Sent to this email address.\n=======================================================================\n
INVOICE NUMBER: $invnumb\n\n
$line1\n$line2\n$line3\n$line4\n$line5\n$line6\n=======================================================================\n
INVOICE DATE:$invdate\n
SERVICE DATES: $invstart Thru $invend\n\n
INVOICE STATUS: $invstatus\n
DATE PAID: $paiddate\n
=======================================================================\n
ACCOUNT ID: $acctid\n\n
$bill_company\n
$bill_name\n
$bill_address\n
$bill_city, $bill_state, $bill_zip. $bill_country\n
=======================================================================\n
$services\n\nINVOICE TOTAL: $invtotal\n
=======================================================================\n\n
If You Have any Questions Regarding This Invoice Please Contact Our Billing Department at: $sysbillemail\n\n
Thank You\n\n";
mail($sendemail, $subject, $message, "From: ".$fromName."<".$fromAddress.">");
header("Location: invoice_sent.php"); ?>
As I originally Mentioned if I use echo with this same code it works. So this works..
<?php
$query = "SELECT * FROM inv_services WHERE invid = '$invid'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$invtype = $row[invtype];
$invdesc = $row[invdesc];
$invdomain = $row[invdomain];
$invcost = $row[invcost];
$i++;
echo "$invtype $invdesc $invdomain $invcost<br>";} ?>
What I need is for the same output as the above code produces to be in the email in the place I have $services (in the $message = "")
I really appreciate any help or suggestions.