我在一个 PHP 网站上有一个购物车,一切都很好,但我正在尝试创建一个函数,将购物车的内容通过电子邮件发送到指定的地址。
我的电子邮件工作完美,但我很难让购物车中的每件商品都显示出来。
到目前为止,我有下面的代码。问题在于我在 $email_body 变量中添加了一个 foreach 循环,但由于这是我显示购物车的方式,我认为这将是创建电子邮件的方式。谁能看到我哪里出错了?
提前致谢
<?php
session_start();
//echo "<br />CART: " . $_SESSION["cart"] . "<br />";
require_once('Connections/ships.php');
// Include functions
require_once('inc/functions.inc.php');
$cart = $_SESSION["cart"];
$visitor_email = $_POST['email'];
$arrCart = explode(",", $cart);
// Open db
mysql_select_db($database_ships, $ships);
// Grab first (and only) row from query
$row = mysql_fetch_array($cart_items);
//create the variables
$email_from = 'anemailaddress@gmail.com';//<== update the email address
$email_subject = "Ship Image Information Request";
$email_body = "You have received a request for Ship Information from:" . $visitor_email. "They would like information on the following ships" .
"foreach ($arrCart as $cart_item) {
$sql = 'SELECT ship_id, ship_name, image FROM ship_infomation WHERE ship_id = $cart_item LIMIT 1;';
$cart_items = mysql_query($sql, $ships) or die(mysql_error()) $row['ship_name'];
}";
$to = "anemailaddress@gmail.com";//<== update the email address
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.php');
?>