我不知道如何通过电子邮件发送整个购物车阵列。我尝试使用 print_r 函数,但结果中只得到一项。
任何帮助将不胜感激。
<?php session_start(); ?>
<?php
if (!isset($_SESSION['cart']) || (count($_SESSION['cart']) == 0)) {
echo '<p>Your shopping cart is empty, so <a href="L14O1_buy.php">get shopping</a>.</p>';
} else {
echo '<table>
<tr>
<th>Product</th>
<th>Cost</th>
<th>Units</th>
<th>Subtotal</th>
</tr>';
$total = 0;
foreach($_SESSION['cart'] as $item) {
echo "<tr>
<td>{$item['item']}</td>
<td>\${$item['unitprice']}</td>
<td>{$item['quantity']}</td>
<td>$".($item['unitprice'] * $item['quantity'])."</td>
</tr>";
$total += ($item['unitprice'] * $item['quantity']);
}
echo '</table>';
echo "<p>Grand total: \$$total</p>";
}
?>
<?php
$to = 'blah@gmail.zzz';
$subject = 'the subject';
$body = print_r($item);
$headers = 'From: blah@gmail.zzz' . "\r\n" .
'Reply-To: blah@gmail.zzz' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $body, $headers);
?>