I have created a shopping cart and need to know how to send the products and total they have selected to them in an email?
I am using this function to display the contents of the cart to the user on the screen.
function display_checkout_cart($cart, $change=true, $images = 1){
//display items in shopping cart
//optionally allow changes (true or false)
//optionally include images
echo("
<table width='750' border='0' cellspacing='0' cellpadding='0'>
<form action='/project/checkout.php' method='post'>
<tr>
<td width='368'><p><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><b>Product Name</b></font></p>
<p> </p></td>
<td width='138'><p><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><b>Price</b></font></p>
<p> </p></td>
<td width='194'><p><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><b>Qty</b></font></p>
<p> </p></td>
<td width='50'><p><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><b>Total</b></font></p>
<p> </p></td>
</tr>
");
//display each item as a table row
foreach($cart as $prod['productID'] => $qty){
$prodInfo = mysql_fetch_array(mysql_query("select productPrice, productName from products where productID = ".$prod['productID'].""));
echo ("
<tr>
<td><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>".$prodInfo['productName']."</font></td>
<td><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>\$".number_format($prodInfo['productPrice'], 2)."</font></td>
<td>");
//if we allow changes, quantities are in text boxes
if($change==true){
echo("
<font size='1' face='Verdana, Arial, Helvetica, sans-serif'><input type='text' name='".$prod['productID']."' size='2' value='".$qty."'>add/remove</font></td>
");
}else{
echo(" <font size='1' face='Verdana, Arial, Helvetica, sans-serif'>$qty</font> ");
}
echo("
<td><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>\$".number_format($prodInfo['productPrice'] * $qty, 2)."</font></td>
</tr>
");
}
echo("
<tr>
<td colspan='4'><hr width='750' noshade><br></td>
</tr>
");
//display total row
echo("
<tr>
<td width='368'><p> </p></td>
<td width='138'><p> </p></td>
<td width='194'><b><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>".$_SESSION['items']."</font></b></td>
<td width='50'><b><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>\$".number_format($_SESSION['total_price'],2)."</font></b></td>
</tr>
");
echo (" </form></table>");
}
Basically I want to be able to add that function or what is in it to the email body.
This is what the page looks like that will send the email and also display the order back to them on the screen.
<?
include ('connect_var.php');
include ('connect.php');
include ('functions.php');
session_start();
$firstName = $_SESSION['firstName'];
$lastName = $_SESSION['lastName'];
$email = $_SESSION['email'];
//if the cart has items display them
if($_SESSION['cart']&&array_count_values($_SESSION['cart']))
{
display_checkout_cart($_SESSION['cart'], false, 0);
}
echo("
<html>
<head>
<title>Process Order</title>
</head>
<body>
<br><br><br><br><br><br><br><br>
<font size='1' face='Verdana, Arial, Helvetica, sans-serif'>
Thank you for shopping with us <b>$firstName $lastName</b>. Your order has been placed.<br>
An email has been sent to <b>$email</b> confirming your order and total.<br>
Please print a copy of it to keep for your records.</font>
</body>
</html>
");
$useremail="$email";
$subject="Order Details";
$header = "From: order@xyzcompany.com\r\n";
$header .= "X=Mailer: PHP/";
$body="Here are the details of your order:
//this is where the order details should be.
";
mail ($useremail, $subject, $body, $header);
exit;
?>
I hope this makes sense and that someone can help me in this matter.
Thanks