output page to an email

I want to output the information from this page to a email: with what I have I only get the last line of the output.

[php][

<?php $grandTotal = 0; $connect =odbc_conmation from this nect("removed"); if(!$connect) { exit("Connection Failed: " . $connect); } #echo 'Open Orders'; $sql="select case when rtrim(so.uompfurnhold) in ('0','1','') then 'Released' when rtrim(so.uompfurnhold) ='2' then 'Product' when rtrim(so.uompfurnhold) ='3' then 'Minimal' when rtrim(so.uompfurnhold) ='4' then 'Customer' else 'GO' end as OrdStatus, count(SO.ompSalesOrderID) as orders,round(sum(SO.ompOrderSubTotalBase),2) as total FROM m1_kf.dbo.SalesOrders SO Where so.ompClosed !=-1 Group by case when rtrim(so.uompfurnhold) in ('0','1','') then 'Released' when rtrim(so.uompfurnhold) ='2' then 'Product' when rtrim(so.uompfurnhold) ='3' then 'Minimal' when rtrim(so.uompfurnhold) ='4' then 'Customer' else 'GO' end "; $result =odbc_exec($connect,$sql); if(!$result){ exit("Error in SQL"); } echo "Open Orders ". date("m-d-Y") ; echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; while (odbc_fetch_row($result)) { $OrdStatus=odbc_result($result,"OrdStatus"); $orders=odbc_result($result,"orders"); $total=odbc_result($result,"total"); $num = number_format($total, 2, '.', ','); $grandTotal += $total; echo ""; echo ""; echo ""; echo ""; echo ""; } #$num2 = number_format( $grandTotal, 2); #echo "Grand Total: $num2"; odbc_close($connect); //******************************************************************************** require_once "Mail.php"; require_once "Mail/mime.php"; $from = "removed"; #$to = "removed"; $to = "removed"; #$subject = "Status\r\n\r\n"; $subject=''; $text=""; $html = ""; $crlf = "\n"; $mime = new Mail_mime($crlf); $mime->setTXTBody($text); $mime->setHTMLBody($html); $host = "smtp.gmail.com"; $username = "removed"; $password = "removed"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $body = $mime->get(); $body="$OrdStatus > $num"; #$body ='Get the Info'; $headers = $mime->headers($headers); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo(" " . $mail->getMessage() . " "); } else { echo(" Message successfully sent! "); echo $text; } ?> [/php]
Status Orders Total
$OrdStatus$orders$num

Try using concatenation…

Change this: $body = “$OrdStatus > $num”; // Line 98 in your post

To this: $body .= “$OrdStatus > $num”;

Or, even better: $body .= $crlf . “$OrdStatus > $num”; // Fixes run-on text…

I changed it to

$body .= $crlf . “$OrdStatus > $num”;

But I still only get last line of output in the email

Does this need to be in the while loop???

Yes, Kat !

So, I reviewed your code further. You run a query to get the orders. Then, you parse thru them to create a
table for display. Next you send an email using the last order. So, you code works as it is programmed…

To add a list to send in an email of all the orders, you would have to do something like this… ( loosely… )
Change
while (odbc_fetch_row($result)) {
build table…
}
To something like:
$order_list="";
while (odbc_fetch_row($result)) {
build table…
$order_list .= $OrdStatus . " " . $orders . " " . $num . $crlf;
}
Then, when you create your $body for the email, use the $order_list which would be all of the order info…
Another way would be to set the FETCH_ROW to a variable inside the WHILE and then loop thru the info
a second time. But, I think that is a waste of time… This way only uses two extra lines…

Hope that helps

Perfect. Thanks

Great! A nice warm feeling to solve a programming puzzle…

CYA in the “Bitstream” , Kat !

Sponsor our Newsletter | Privacy Policy | Terms of Service