我在一个 JS 购物车网站上工作,我正在尝试使用 php 邮件将购物车详细信息发送到结账功能上的邮件,这里我通过 ajax 将我的购物车详细信息传递给 php。
在 php 中,当尝试使用 foreach 发送所有购物车值时,我只能接收购物车的最后一行,因为 foreach 正在替换以前的值
如何检索购物车值并以某种格式发送它们
js
function SendMail() {
var tableContent = localStorage.getItem('productsInCart');
$.post('read.php', {tableContent: tableContent}, function (data) {
console.log(tableContent);
});
}
php
if (isset($_POST['tableContent'])) {
$tableContent = json_decode($_POST['tableContent']);
foreach ($tableContent as $tableContent) {
$name = ($tableContent->name);
$price = ($tableContent->price);
$quantity = ($tableContent->inCart);
}
$mailTo = "xxxxxxxxxxxxx";
$Subject = " order details ";
$headers = "from :" . $contact;
$txt = "New registration \n Item:" . $name . "\n Quantity:" . $quantity . "\n Price:" . $price . "\n\n\n CUSTOMER DERAILS\n\n Name:" . $contact . "\n Reg No:" . $reg;
mail($mailTo, $Subject, $txt, $headers);
header("location: read.php?mailsend");
}
慕后森