<?php
/*
* SimpleCartjs email
*/
// DATA FROM EMAIL FORM INPUT FIELDS
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$comment = $_POST['comment'];
// STARTING EMAIL BODY
$body = '';
$body .= '<html><body>';
$body .= 'Order submission and details.<br /><br />';
$body .= '<img src="https://lh6.googleusercontent.com/-rid5-_qM_bU/VCWj5yuJDII/AAAAAAAAAGI/_xacTWTKXfU/s350/logo5.png" alt="Woven And Folks" />';
$body .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$body .= "<tr style='background: #6c96df;'><td><strong>ORDER BY:</strong> </td><td>";
$body .= "<tr style='background: #eee;'><td><strong>First Name:</strong> </td><td>" .$_POST['first_name'] . "</td></tr>";
$body .= "<tr style='background: #eee;'><td><strong>Last Name:</strong> </td><td>" . $_POST['last_name'] . "</td></tr>";
$body .= "<tr style='background: #eee;'><td><strong>Email:</strong> </td><td>" . $_POST['email'] . "</td></tr>";
$body .= "<tr style='background: #eee;'><td><strong>Phone:</strong> </td><td>" . $_POST['phone'] . "</td></tr>";
$body .= "<tr style='background: #eee;'><td><strong>Address:</strong> </td><td>" . $_POST['address'] . "</td></tr>";
$body .= "<tr style='background: #eee;'><td><strong>Postal Code:</strong> </td><td>" . $_POST['postcode'] . "</td></tr>";
$body .= "<tr style='background: #eee;'><td><strong>Comments:</strong> </td><td>" . $_POST['comments'] . "</td></tr>";
$body .= "<tr style='background: #9fb4f8;'><td><strong>ORDER DETAILS:</strong> </td><td>";
// LOOPING FOR EACH ITEMS IN SHOPPING CART DATA
$curr = $_POST['currency'];
$content = $_POST;
// STARTING THE LOOP
for($i=1; $i < $content['itemCount'] + 1; $i++) {
$name = 'item_name_'.$i;
$option = 'item_options_'.$i;
$quantity = 'item_quantity_'.$i;
$price = 'item_price_' .$i;
// CALCULATE MULTIPLE ITEMS PER QUANTITY
$amount = $content[$quantity]*$content[$price];
$grandTotal += $amount;
// DISPLAY RESULT FOR EACH ITEM
$body .= '=============================================================<br />';
$body .= '<b>Product #'.$i.'</b><br />';
$body .= 'Item Name: '.$content[$name].'<br />';
$body .= 'Item Description: '.$content[$option].'<br />';
$body .= 'Item Quantity: '.$content[$quantity].'<br />';
$body .= 'Item Price: '.$curr.' '.number_format($content[$price], 2, '.', '').'<br />'; $body .= 'Item Amount: '.$curr.' '.number_format($amount, 2, '.', '').'<br />'; $body .= '=============================================================<br />';
$body .= '<br />';
} // ENDING THE LOOP
$shipping = $_POST['shipping'];
$tax = $_POST['tax'];
$body .= 'Sub Total: $'.number_format($grandTotal, 2, '.', '').'<br />'; $body .= 'Shipping Charges: '.$curr.' '.number_format($shipping, 2, '.', '').'<br />'; $body .= 'Tax: '.$curr.' '.number_format($tax, 2, '.', '').'<br />';
// CALCULATE SUB TOTAL ITEMS
$sub_total += $grandTotal;
// CALCULATE TOTAL
$grand_total = $sub_total + $shipping + $tax;
$body .= "<tr style='background: #e8c090;'><td><strong>ORDER SUMMARY:</strong> </td><td>";
// DISPLAY THE TOTALS/SHIPPING/TAX
$body .= '=============================================================<br />';
$body .= '<b>TOTAL: '.$curr.' '.number_format($grand_total, 2, '.', '').'</b><br />'; $body .= '=============================================================<br />';
$body .= '<br />';
// LOADING POST DATA FOR PAYMENT SECTION
$body .= "<tr style='background: #e890d0;'><td><strong>PAYMENT METHODS:</strong> </td><td>";
$bank1 = $_POST['bank1'];
$bank1_acc_no = $_POST['bank1_acc_no'];
$bank1_acc_name = $_POST['bank1_acc_name'];
// DISPLAY PAYMENT METHOD DATA
$body .= '=============================================================<br />';
$body .= 'Bank: '.$bank1.'<br />';
$body .= 'Account number: '.$bank1_acc_no.'<br />';
$body .= 'Name on Account: '.$bank1_acc_name.'<br />';
// CONTINUE WITH AVAILABLE VARS
$body .= '=============================================================<br />';
$body .= '<br />';
// LOADING POST DATA FOR NOTES
$note1 = $_POST['note1'];
$note_detail1 = $_POST['note_detail1'];
// OUTPUT VARS HERE FOR GENERAL NOTES
$body .= "<tr style='background: #adf89f;'><td><strong>GENERAL NOTES:</strong> </td><td>";
$body .= '=============================================================<br />';
$body .= ''.$note1.'<br />';
$body .= ''.$note_detail1.'<br />';
// CONTINUE WITH AVAILABLE VARS
$body .= '=============================================================<br />';
$body .= '<br />';
$body .= '</body></html>';
// BEGIN TO SEND EMAIL
// GRABS POST DATA FOR SUCCESS/ERROR/SHOP URLS & EMAIL
$shop_thankyou = $_POST['shop_thankyou'];
$shop_sendFail = $_POST['shop_sendFail'];
$shop_email = $_POST['shop_email'];
// SENDERS EMAIL GRABS FROM THE FORM
$to = $email;
$subject = 'Order Submission';
// BECAUSE WE WANT THE EMAIL TO OUTPUT IN HTML
// MAIL HEADERS MUST HAVE CONTENT-TYPE
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// EMAIL TO SENDER
$headers .= 'To: '.$first_name.' '.$last_name.' <'.$email.'>' . "\r\n";
// SETTING THE REPLY-TO
//$headers .= 'Reply-To: '.$shop_bizname.' <'.$shop_email.'>' . "\r\n";
// EMAIL FROM THE OWNER
$headers .= 'From: '.$shop_bizname.' <'.$shop_email.'>' . "\r\n";
// SEND A COPY TO OWNER
$headers .= 'Cc: '.$shop_email.'' . "\r\n";
// SEND THE MAIL
mail($to, $subject, $body, $headers);
// IF THE EMAIL CAN NOT SEND
Header('Location: http://'.$shop_sendFail.''); // REDIRECTS TO ERROR PAGE } else {
// SEND THE MAIL + REDIRECTS
Header('Location: http://'.$shop_thankyou.''); // REDIRECTS TO SUCCESS PAGE AFTER }
?>