0

我正在尝试将 SimpleCartjs 中购物车中的所有数据发送到电子邮件。基本上我更喜欢将其发送给客户的电子邮件以确认他的订单。所以现在我让它工作了,但我似乎无法发送总计,这是所有内容的总和(成本 + 税 + 运费)。我可以将它回显到屏幕上,但邮寄时,grandTotal 不会发送。有任何想法吗?到目前为止,这是我的代码。body 字段末尾的 grandTotal 就在那里,但我不知道如何获取它的值:

 $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);
4

1 回答 1

0

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

于 2014-12-20T01:54:08.583 回答