Page 1 of 1

email query results

Posted: Tue Oct 31, 2006 2:52 pm
by danxavier
This neat little PHP script shows a row items that were chosen from a shopping cart. The problem is that the script just shows the results, and doesn't have a routine to email me or the user what they have picked. Does anyone have the code I can put in the script so that the user can type in their name and email address, and when they push submit, it sends them an email of the items and prices, as well as to me? I'm struggling. Thanks. If you want to see how it works, please go to http://www.altusair.com/cart/phpCart_shop.php

Code: Select all

<?
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>phpCart</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="phpCart_style.css" rel="stylesheet" type="text/css">
</head>

<body>
				<form name="update" method="post" action="phpCart_manage.php">
				<table width="50%"  border="0" cellspacing="0" cellpadding="0">
				<tr bgcolor="#EEEEEE">
				<td width="10%" class="bottomline">&nbsp;</td>
				<td width="5%" class="bottomline"><strong>Qty</strong></td>
				<td width="5%" class="bottomline"><strong>LCode</strong></td>
				<td width="50%" class="bottomline"><strong>Product</strong></td>
				<td width="10%" class="bottomline"><strong>Image</strong></td>
				<td width="10%" class="bottomline"><strong>Price</strong></td>
				<td width="10%" class="bottomline"><strong>Line Total </strong></td>
				</tr>
<?
include "functions_cart.php";
$totalvalue = 0;

session_start();
// If no sessions has been started $_SESSION["cart"] equals null, thus showing the message no items.
if (!isset($_SESSION["cart"])) {
	$_SESSION["cart"] = NULL;
}

if (validate() == TRUE && $_SESSION["cart"] != NULL) {
					
	foreach ($_SESSION["cart"] as $key => $session_data) {
		
		list($ses_id, $ses_quan) = $session_data;
						
			// call database connect function
			db_connect();
			$sel_products = mysql_query("SELECT * FROM $mysql_tablename WHERE id=".$ses_id."");
			$item = mysql_fetch_array($sel_products);
				
			$totalvalue = $totalvalue + ($item["price"]*$ses_quan);
			$subtotal = ($item["price"]*$ses_quan);
					
	?>
				<tr>
				<td class="dividingborder"><a href="<? echo "phpCart_manage.php?act=del&pid=".$ses_id; ?>"><img src="img/icon_del.gif" width="13" height="13" border="0"></a></td>
				<td class="dividingborder"><input name="newquan[]" type="text" id="newquan[]4" value="<? echo $ses_quan; ?>" size="5" maxlength="4">
				<input name="eid[]" type="hidden" id="eid[]" value="<? echo $ses_id; ?>"></td>
				<td class="dividingborder"><? echo $item["code"]; ?></td>
				<td class="dividingborder"><? echo $item["product"]; ?></td>
				<td class="dividingborder"><? echo '<img src="'.$item["picurl"].'" width="auto" height="auto" alt="' . $item["product"] . ' Image"'; ?></td> 
 
				<td class="dividingborder"><? echo $cur_symbol."".number_format($item["price"], 2, '.', ''); ?></td>
				<td class="dividingborder"><? echo $cur_symbol."".number_format($subtotal, 2, '.', ''); ?></td>
				</tr>
	<?
	} // end foreach loop
	
} elseif ($_SESSION["cart"] == NULL) {

	echo "<td colspan=\"5\"><center><p>Your basket is currently empty.</p></center></td>";
			
} else {
	
	echo "<td colspan=\"5\"><center><p>Unknown Error.</p></center></td>";

}
	?>
				<tr>
				<td> <img src="img/icon_del.gif" width="13" height="13"> - delete</td>
				<td><? if ($_SESSION["cart"] != NULL) { echo "<input name=\"UpdateChg\" type=\"submit\" id=\"UpdateChg\" value=\"Update\">"; } ?></td>
				<td><a href="phpCart_shop.php">Add More Avionics</a></td>
				<td><strong>Stack Total</strong></td>
				<td><? echo $cur_symbol."".number_format($totalvalue, 2, '.', ''); ?></td>
				</tr>
				</table>
				</form>

</body>
</html>
<?
ob_end_flush();
?>

Posted: Tue Oct 31, 2006 3:02 pm
by RobertGonzalez
Have a look at the mail() function (for guidance) and Swiftmailer for a great mailing application.