无法通过PHPmailer将会话数据发送到电子邮件

无法通过PHPmailer将会话数据发送到电子邮件,php,email,phpmailer,eval,session-variables,Php,Email,Phpmailer,Eval,Session Variables,我试图在我的网站上成功下订单后发送电子邮件,但是电子邮件会发送,但存储在会话变量$u SESSION[cart]中的详细信息不会随之发送 这是我的php代码 require(ROOT_PATH . 'phpmailer/src/Exception.php'); require(ROOT_PATH . 'phpmailer/src/PHPMailer.php'); require(ROOT_PATH . 'phpmailer/src/SMTP.php'); // Instantiation a

我试图在我的网站上成功下订单后发送电子邮件,但是电子邮件会发送,但存储在会话变量$u SESSION[cart]中的详细信息不会随之发送

这是我的php代码

require(ROOT_PATH . 'phpmailer/src/Exception.php'); 
require(ROOT_PATH . 'phpmailer/src/PHPMailer.php'); 
require(ROOT_PATH . 'phpmailer/src/SMTP.php');
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER;                     
// Enable verbose debug output
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Hostname = '197.210.53.47';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPAuth = true;
$mail->Username = "browynlouis2@gmail.com";
$mail->Password = '081';
//Recipients
$mail->setFrom('browynlouis2@gmail.com', 'Sativa Merchandise');
$mail->addAddress($_SESSION["order_details"]["email"]);               // Name is optional
$mail->addReplyTo('browynlouis2@gmail.com', 'Sativa Merchandise');
// Content
$mail->isHTML(true);                                 
// Set email format to HTML

$body = '<html lang="en"><head></head><body>';

    $body .= '<section class="shop checkout section" style="text-align:center; padding:20px; background:white"><div class="container"><div class="inner-top"><div class="row"><div><div class="inner">';
    
    $body .= '<a href="localhost:8080/phpmyadmin/online_store/index.php"><img src="cid:logo" width="40" height="50"></a><br><br><h1>ORDER CONFIRMATION</h1/><p style="font-weight: lighter;color: grey;font-size:18px;line-height:28px"> You are getting this email in regards to your successful order on www.sativamerch.com with order ID <b>'. $_SESSION["order_details"]["order_id"] .'</b>. You can view your <span style="color:#0088CC">order details</span> below.</p>';

    
     $body .= '<div style="text-align:center;width:100%;"><?php foreach($_SESSION["cart"] as &$list) { ?> ';

    
    $mail->AddEmbeddedImage('admin/assets/img/products/'. $list["image"] . '', ''. $list["image"] . '');


     $body .= '<div class="product" style="margin:1%;"><img src="cid:'. $list["image"] . '" width="100px" height="120px" style="border:none"><div class="product-content"><h3>'. $list["name"] .'</h3><span style="font-weight: lighter;font-size:15px;line-height:28px">'. $list["price"] .' </span><br><span style="font-weight: lighter;font-size:15px;line-height:28px">'. $list["quantity"] .' X '. $list["price"] .' = '. $list["quantity"] * $list["price"] .' </span><br></div>';

   $body .= '<?php } ?></div>';

   $body .= '<br><br><div class="details"><h3>SHIPPING DETAILS</h3><p style="font-size:18px"><b>NAME</b></p><span style="font-weight: lighter;font-size:15px;">N8,000 </span><br><p style="font-size:18px"><b>EMAIL</b></p><span style="font-weight: lighter;font-size:15px;">N8,000 </span><br><p style="font-size:18px"><b>PHONE</b></p><span style="font-weight: lighter;font-size:15px;">N8,000 </span><br><p style="font-size:18px"><b>CITY</b></p><span style="font-weight: lighter;font-size:15px;">N8,000 </span><br><p style="font-size:18px"><b>STATE</b></p><span style="font-weight: lighter;font-size:15px;">N8,000 </span><br><p style="font-size:18px"><b>ADDRESS Line 1</b></p><span style="font-weight: lighter;font-size:15px;">N8,000 </span><br><p style="font-size:18px"><b>ADDRESS Line 2</b></p><span style="font-weight: lighter;font-size:15px;">N8,000 </span><br><p style="font-size:18px"><b>NIGERIA</b></p><span style="font-weight: lighter;font-size:15px;">N8,000 </span><br><p style="font-size:18px"><b>ZIP</b></p><span style="font-weight: lighter;font-size:15px;">N8,000 </span><br><p style="font-size:18px"><b>COMPANY</b></p><span style="font-weight: lighter;font-size:15px;">N8,000 </span><br></div></div>';

    
    $body .= '</div></div></div></div></div></section></body></html>';
    
    $mail->Subject = 'ORDER CONFIRMATION : Your order with ID '. $_SESSION["order_details"]["order_id"] .' has been placed';
    $mail->AddEmbeddedImage('admin/assets/img/logo.jpg', 'logo');
    $mail->Body    = $body;
    $mail->AltBody = nl2br(strip_tags($body));
    if (!$mail->send()) {
    $status = "YOUR ORDER COULDN'T BE PLACED";
    } else {
        // Rest code

    } 
这是一张电子邮件的图片,可以更好地显示我所说的内容


您正在错误地构建内容。这是行不通的:

$body .= '<div style="text-align:center;width:100%;"><?php foreach($_SESSION["cart"] as &$list) { ?> ';
单引号内的PHP标记将被忽略,如果您检查接收到的消息的源,这一点应该很明显。返回PHP模式运行该代码,如下所示:

$body .= '<div style="text-align:center;width:100%;">';
foreach($_SESSION["cart"] as &$list) {
    $body .= //stuff from the session added here...
}

如果在使用$body之前先对其进行评估,则可以使用原始代码,但这样做速度较慢,而且有点危险。

您的内容构建不正确。这是行不通的:

$body .= '<div style="text-align:center;width:100%;"><?php foreach($_SESSION["cart"] as &$list) { ?> ';
单引号内的PHP标记将被忽略,如果您检查接收到的消息的源,这一点应该很明显。返回PHP模式运行该代码,如下所示:

$body .= '<div style="text-align:center;width:100%;">';
foreach($_SESSION["cart"] as &$list) {
    $body .= //stuff from the session added here...
}

如果在使用$body之前先评估$body中的内容,则可以使用原始代码,但这样做会更慢,而且有点危险。

在该脚本中转储$\u会话[cart]时会得到什么?购物车详细信息本身会出现。$\u会话['cart']是否有数据?是的。。如果不是的话,我就不会在我的网站上成功订购到这一点。。我检查了$u会话[cart]的每一个部分,它仍然在适当的位置,请参见这里。至于定价细节。。。您能否在其中一个迭代中共享$list的转储?当您在该脚本中转储$u会话[cart]时,会得到什么?购物车详细信息本身会出现您的$u会话['cart']是否有数据?是的,它有。。如果不是的话,我就不会在我的网站上成功订购到这一点。。我检查了$u会话[cart]的每一个部分,它仍然在适当的位置,请参见这里。至于定价细节。。。你能在一次迭代中共享$list转储吗?绝对正确…绝对正确。。。。