我的项目中有一个while循环查找并列出用户在购物车中的数据库中的项目(行)。
使用phpmailer body,发送生成内容的最佳方式是什么?
$m -> Body = "I want my different cart items to be echoed here";
我想要添加任何html $m -> isHTML(true);
。
邮件系统我的工作完美,但我希望能够发送这些内容(如果可能的话,以这种格式发送):
while($cart_item = mysqli_fetch_assoc($fetch_cart_contents)){
$cart_item_list = $cart_item['product_id_list'];
$cart_corresponding_quantity = $cart_item['product_quantity_list'];
$cart_item_price = $cart_item['order_total'];
echo "<tr>
<td>$cart_corresponding_quantity</td>
<td>$cart_item_list</td>
<td>$cart_item_price</td>
</tr>";
}
P.S。我知道如何用php连接变量,但这是我第一次尝试phpmailer,而while循环让我失望......
======
编辑。到目前为止我已经
了while($cart_item = mysqli_fetch_assoc($fetch_cart_contents)){
$cart_item_list = $cart_item['product_id_list'];
$cart_corresponding_quantity = $cart_item['product_quantity_list'];
$cart_item_price = $cart_item['order_total'];
$emailbody .= "<tr>
<td>$cart_corresponding_quantity</td>
<td>$cart_item_list</td>
<td>$cart_item_price</td>
</tr>";
}
稍后在文档中我这样做来设置正文。
$m -> Body = "<h2>Order Details</h2><br>".$emailbody."<br><br>-- end of order --";
答案 0 :(得分:0)
正如@Kenney所说,
$emailbody .= "<tr>
<td>$cart_corresponding_quantity</td>
<td>$cart_item_list</td>
<td>$cart_item_price</td>
</tr>";
连接while循环内的新项,并将消息体设置为$emailbody
答案 1 :(得分:0)
您必须先声明$emailbody
的值。以下就足够了。
$emailbody = '';
$emailbody .= "<tr>
<td>$cart_corresponding_quantity</td>
<td>$cart_item_list</td>
<td>$cart_item_price</td>
</tr>";