0

I'm trying to send all data from the shopping cart in SimpleCartjs to an email. Basically I prefer to send it to a clients email for confirmation of his order. So for now I got it working, but I cannot seem to send the grandTotal, which is the sum of everything (cost + Tax + Shipping). I am able to echo it to the screen, but when mailing it the grandTotal will not send. Any ideas? here is my code so far. The grandTotal in the end of the body field is just there, But I dont know how to get its value:

 $send = $_GET['send'];
 $to = 'name@myname.com';
 $subject = 'Your Tea shopping Cart';
 $content = $_POST;
 $body = '';

 for($i=1; $i < $content['itemCount'] + 1; $i++) {
     $name = 'item_name_'.$i;
     $quantity =  'item_quantity_'.$i;
     $price = 'item_price_'.$i;
     $tax = $_POST['taxRate'];
     $ship = $_POST['shipping'];
     $total = $content[$quantity]*$content[$price];
     $iva = $content[$price]*$tax;
     $subtotal = $total + $ship + $iva;

     $body .= 'item #'.$i.':';
     $body .= $content[$name].'<br>';
     $body .= $content[$quantity].'Un.:  '.$content[$price].'Euros<br>';
     $body .= 'IVA :   '.$content[$price]*$tax.'Euros<br>';
     $body .= 'Shipping: '. $ship.'Euros<br>';
     $body .= 'Total: '.$subtotal.'Euros<br>';
     $body .= '------------------------------------<br>';    
 };
 $body .= 'Total: '.$grandTotal;

 $headers = 'From: name@myname.com' . "\r\n" .
            'Reply-To: name@myname.com' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
 $headers .= "MIME-Version: 1.0\r\n";
 $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

 mail($to, $subject, $body, $headers);
swbandit
  • 1,986
  • 1
  • 26
  • 37
Eddy
  • 1
  • 1
  • Your tax calculation seems to be incorrect. It should be TAX = PRICE * QUANTITY * TAXRATE. Not TAX = PRICE * TAXRATE. – swbandit Dec 20 '14 at 01:49
  • Where is your `$grandTotal` initialized? Or do you mean `$content['grandTotal]`? – Hugo B. Jan 13 '15 at 15:53

1 Answers1

0

First initialize $grandTotal = 0; before the for-loop. Then, inside the for-loop, after calculating the subtotal, add $grandTotal = $grandTotal + $subTotal;

swbandit
  • 1,986
  • 1
  • 26
  • 37