Page 1 of 1

(solved) emailing array output URGENT!!

Posted: Thu Mar 16, 2006 10:01 pm
by thomasdaly
I hope someone can help me with this, I have been trying for hours.

I am developing a customised ebay checkout system for use off-ebay. The info is passed to the script via ebay's email autotext (more info http://pages.ebay.com.au/help/sell/autotext.html) from within a checkout link in the winning bidder email.

During the checkout process, if I want to display the order contents, I just include this file: disporder.php

Code: Select all

#Retrieve order info
$query = "select * from ebayordersitems where orderid = '$orderid'";
$result = mysql_query($query) or die(mysql_error());
$numresults = mysql_num_rows($result);

#set order calculation variables
$total = '0';
$qty = '0';

#display it
echo '
<table border="0" cellpadding="3" cellspacing="2" class="table" align="center">
<tr><td bgcolor="#CCCCCC" colspan="5"><b>&nbsp;Your Order:</b></td></tr>
<Tr bgcolor="#CCCCCC"><td><b>Item:</b></td><td><b>Title:</b></td><td><b>Qty:</b></td><td><b>$Closing:</b></td><td><b>$Total:</b></td></Tr>
';


for ($i=0; $i < $numresults; $i++)
{
$i+1;
$row = mysql_fetch_array($result);
$itemid2 = $row[1];
$items = mysql_query("select * from ebayitems where ebayid = '$ebayid' and item = '$itemid2' limit 1") or die(mysql_error());
$itemsrow = mysql_fetch_row($items);
$subtotal = $itemsrow[3] * $itemsrow[4];
$table = '<table border=0 cellpadding=0 cellspacing=0><tr><td>';
echo '<tr bgcolor="#FFFFFF"><td><a href="http://cgi.ebay.com.au/ws/eBayISAPI.dll?ViewItem&rd=1&item='.$itemsrow[1].'&ssPageName=STRK:MESE:IT" target="_blank" class="table">
'.$itemsrow[1].'</a></td><td>'.$itemsrow[2].'</td>
<td>'.$itemsrow[4].'</td><td align="right">'.$itemsrow[3].'</td><td><b>'.$table.'$</td><td width=60 align="right">'.$subtotal.'</td></tr></table></b></td></tr>';

$total = $total + $subtotal;
$qty = $qty + $itemsrow[4];

}
$additionals = $qty -1;
$postage = '5.90' + ($additionals * 1.00);
echo '
<tr bgcolor="#FFFFFF"><td></td><td>Main Postage Component</td><td>1</td><td></td><td><b>'.$table.'$</td><td align="right" width=60>5.90</td></tr></table></b></td></tr>
<tr bgcolor="#FFFFFF"><td></td><td>Additional Items Postage</td><td>'.$additionals.'</td><td></td><td><b>'.$table.'$</td><td align="right" width=60>'.$additionals.'.00</td></tr></table></b></td></tr>
';
$total = $total + $postage;
echo '
<tr bgcolor="#CCCCCC"><td colspan="2"><b>Totals:</b></td><td><b>'.$qty.'</b></td><td></td><td>'.$table.'<b>$</td><td align="right" width=60><b>';printf ("%01.2f", $total);
echo '</b></td></tr></table></b></td></tr>
';
?>
</table><br><br>

This works fine (its a little sloppy I know, and probably not to standard but it works)

At the end of the checkout process, I want to email the customer with a summary of their order which includes displaying the contents of it. How do I include the output of this file in a HTML email?

I have come accross the following function, but I don't know how to use it, or how it works. Any help would be appreciated

Code: Select all

function IncludePage($pagename,$tag,$replace,$report="") {
	global $PAGEROOT;
	if (strstr($pagename,"..")) { echo "error"; return; }

	$fname = "$PAGEROOT/$pagename";
	$fd = fopen($fname,"r");
	if (!$fd) {
		echo "\n<BR>Parser could not open $fname";
		return;
	}
	$contents = fread($fd,filesize($fname));

	$newpage=$contents;

	for ($i=0; $i<count($tag); $i++) {
		//echo "\n<BR>$i. $tag[$i]";
		$arr = explode($tag[$i],$newpage); 
		for ($j=0; $j<count($arr); $j++) {
			if ($j==0) $newpage="";
			$newpage.=$arr[$j];
			if ($j!=count($arr)-1) $newpage.=$replace[$i];
		}
	}
	fclose($fd);

	if ($report!="") return $newpage;
		else echo $newpage;
}

Posted: Thu Mar 16, 2006 11:05 pm
by thomasdaly
I just had a thought.

What if I somehow recorded the output of disporder.php into a text file, and then used file_get_contents() to add it to the email?

Posted: Thu Mar 16, 2006 11:11 pm
by feyd
no need to make it a file, output buffering can give it to you in a string.. however I'd suggest rewriting the code for the include such that it did not echo/dump text to output, instead had a function return the output for display anywhere you'd like.

ob_start() will get you started..

Posted: Thu Mar 16, 2006 11:13 pm
by thomasdaly
Looks like a winner.

Thanks Heaps, will let you know how it works out.

Posted: Thu Mar 16, 2006 11:30 pm
by thomasdaly
Thankyou soooooo much.

I am very happy. It works no probs.

I've just got to tidy everything up now :(

Thanks Again