What im trying to do is take a cart generated from a site, and have it get emailed. When i run my code, the function runs on the page and doesnt send through email, but it shows up correctly. I cant get the output of my function to store to a variable that will work in the email. Here is the code I have…
function emailcartview() {
$total=0;
$totalvalue=0;
foreach($_SESSION as $name => $value) {
if ($value>0){
if (substr($name, 0, 5)=='cart_'){
$id = substr($name, 5, (strlen($name)-5));
$get = mysql_query('SELECT id, name, cost, item_number FROM mydbname WHERE id='.mysql_real_escape_string((int)$id));
$cart = array();
while ($get_row = mysql_fetch_assoc($get)) {
$cart[] = array(
'hsid' => $get_row['id'],
'cost' => $get_row['cost'],
$cost = $get_row['cost'],
'itemno' => $get_row['item_number'],
'name' => $get_row['name'],
'value' => $value,
$sub = $value*$cost,
$total += $sub,
$totalvalue = $value,
'realsub' => number_format($sub, 2),
);
}
foreach($cart as $index => $record){
global $emailcart;
$emailcart = "Item: {$record['itemno']} - {$record['name']} | Qty: {$record['value']} | Cost: {$record['cost']} x {$record['value']} = {$record['realsub']} <br>";
echo $emailcart;
}
}
}
}
echo "Total : $".number_format($total, 2);
}
$emailSubject = 'Invoice Submission';
$webMaster = 'my_email@blahblah.com';
$companyName = $_POST['companyname'];
$contactName = $_POST['contactname'];
$contactEmail = $_POST['contactemail'];
$teleNumber = $_POST['telenumber'];
$billAddr = $_POST['billaddr'];
$shipAddr = $_POST['shipaddr'];
$neededBy = $_POST['neededby'];
$cartprint .= emailcartview();
$body = "
<br><hr><br>
Company Name: $companyName <br>
Contact Name: $contactName <br>
Contact Email: $contactEmail <br>
Telephone Number: $teleNumber <br>
Billing Address: $billAddr <br>
Shipping Address: $shipAddr <br>
Date Needed: $neededBy <br> <br>
<br><hr><br>
$cartprint";
$headers = "From: ordersubmission@blahblah.com\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
?>
There are probably quite a few remnants of strange things ive tried and havent worked, not the cleanest. Any assistance would be greatly appreciated!!
Tylor.
In function emailcartview you need to generate string rather than echo statement and at the end of function you should return that string.
Check below code: