【发布时间】:2018-06-05 14:04:10
【问题描述】:
我们需要使用结账按钮将购物车通过电子邮件发送回网络版主,让他批准我现在拥有的内容,而不是进行传统的购物车结账,但是当它从数据库中抓取产品时发送电子邮件 它为购物车中的每个行项目发送一封单独的电子邮件 我想要一封包含整个购物车的电子邮件 这很可能是一个循环问题,但似乎无法弄清楚任何帮助将不胜感激`
foreach($_SESSION['shoppingCart'] as $key => $product)
{
if (isset($_POST['checkout']))
{
$result = $this->qry("SELECT * FROM product WHERE Item_num=?", array($product['ID']));
foreach ($result as $row)
{
echo '<tr>';
echo '<td>'.$row['Name'].'</td>';
echo '<td>'.$product['Quantity'].'</td>';
echo '<td>'.$row['Price'].'</td>';
echo '<td>$'.number_format($product['Quantity'] * $row['Price'], 2).'</td>';
echo '<td><form method="POST">
<button type="submit" name="removeFromCart" value="'.$product['ID'].'">
Remove</button></form></td>';
echo '</tr>';
$total = $total + ($product['Quantity'] * $row['Price']);
$price= $row['Price'];
$lprice= $product['Quantity'] * $row['Price'];
$quan= $product['Quantity'];
$name = $row['Name'];
$quantity = $product['Quantity'];
$to = 'ms245@zips.uakron.edu';
$subject = 'order from fatfish aquatic website';
$message = "<html><body>";
$message .= "<table>";
$message .= "<th>Name</th><th>Quantity</th><th>Price</th> <th> line total</th>";
$message .= "<tr style='background: #eee;'><td>'.$name.'</td><td>'.$quan.'</td><td>'.$price.'</td><td>'.$lprice.'</td></tr>";
$message .="123";
$message .= "</table>";
$message .= $total;
$message .= $row['Name'];
$message .= 'shipping address <br>';
$message .= 'phone number <br>';
}
$message .= 'email<br>';
$message .= "</body></html>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ms245@zips.uakron.edu\r\n"."X-Mailer: php";
mail($to, $subject, $message, $headers);
}
}`
【问题讨论】:
-
您的
mail()函数在循环内... -
@mitchell-secaur 我已经为您提供了答案,如果您认为这可以解决您的问题,请考虑将其标记为已接受的答案,谢谢 :)
标签: php html-email shopping-cart