I am using the following to display my shopping cart contents:
<?php function showCart() {
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<form action="cart.php?action=update" method="post" id="cart2">';
$output[] = '<table cellpadding="2" cellspacing="0">';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM tbl_products WHERE prodID = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr class="normal_text">';
$output[] = '<td>Product Name: '.$prodName.'</td>';
$output[] = '<td>Quantity: '.$qty.'</td>';
$subtotal = $price * $qty;
setlocale(LC_MONETARY, 'en_US');
$subprice = money_format('%(#10n', $subtotal) ;
$output[] = '<td>Sub-total: '.$subprice.'</td>';
$total += $price * $qty;
setlocale(LC_MONETARY, 'en_US');
$totalprice = money_format('%(#10n', $total) ;
$output[] = '</tr>';
}
$output[] = '</table>';
$output[] = '<div class="header">Grand total:'.$totalprice.'</div>';
$output[] = '</form>';
} else {
$output[] = '<p class="header"></p>';
}
return join('',$output);
}
?>
To display the shopping cart I simply have:
<?php
echo showCart();
?>
This works great but I have no idea how to email the cart contents being displayed. I have studied the php mail() function but cannot work out how to do this as it is the first time I have ever had to do something of this nature.
Any assistance would be greatly appreciated.