Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在电子邮件正文中插入表_Php_Html - Fatal编程技术网

Php 在电子邮件正文中插入表

Php 在电子邮件正文中插入表,php,html,Php,Html,我写了下面的代码来在ans发送的电子邮件中插入表格。当表格包含1或2个项目时,它们将在2行上显示良好,但如果有2个以上的项目,其余项目将显示在第二行之后,但完全显示在表格的左侧。 我不知道这里怎么了。谢谢你的帮助 <?php $to = "$user->email"; $from = "sales@exemple.com"; //the email address from $headers = "From: ".$from."\r\n"; $headers .= "Conten

我写了下面的代码来在ans发送的电子邮件中插入表格。当表格包含1或2个项目时,它们将在2行上显示良好,但如果有2个以上的项目,其余项目将显示在第二行之后,但完全显示在表格的左侧。 我不知道这里怎么了。谢谢你的帮助

<?php
$to = "$user->email";
$from = "sales@exemple.com"; //the email address from 
$headers  = "From: ".$from."\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$subject = "Your order";
$message = "<html>
        <body>
            <p>Order Details test</p>
            <table style=\"margin-left:50px; text-align:left;\">
                <tr>
                    <th style=\"width:20%; border-bottom:solid 1px #000;\">Item ID</th>
                    <th style=\"width:40%; border-bottom:solid 1px   #000\">Description</th>
                    <th style=\"width:20%; border-bottom:solid 1px #000\">Quantity</th>
                    <th style=\"width:20%; border-bottom:solid 1px #000\">Unit Price</th>
                </tr>
                <tr>";

foreach( $_SESSION["cart_array2"] as $item2)
{
$item_id = $item2["part_id"];
$sql     = mysqli_query( $con, "SELECT * FROM product_description WHERE   product_id='".$item_id."' LIMIT 1;" );

if($row=mysqli_fetch_array($sql))
{
    $message .= "<td>".$item2['part_id']."</td>
                 <td>".$row['name']."</td>
                 <td>".$item2['quantity']."</td>     
                 <td>".$item2['price']."</td></tr>";
  }
}

$message .= "</tr></table></body></html>";
$mailsent = mail( $to, $subject, $message, $headers );

if ($mailsent) {
//echo "<p>Yay! The following data has been sent:<br /><br />";
//echo "<strong>By: </strong> " . $from . "<br />";
//echo "<strong>About:</strong> " . $subject . "<br />";
//echo "<strong>Comments:</strong>" . $message . "<br />";
//echo "</p>";
}
else {
echo "There was an error sending your order confirmation";
}


?>
您的
必须针对以下各项:

if($row=mysqli_fetch_array($sql))
{
$message .= "<tr>
             <td>".$item2['part_id']."</td>
             <td>".$row['name']."</td>
             <td>".$item2['quantity']."</td>     
             <td>".$item2['price']."</td>
              </tr>";
  }
}
if($row=mysqli\u fetch\u数组($sql))
{
$message.=”
“$item2['part_id']”
“$row['name']”
“$item2[‘数量’]”
“$item2[‘价格’]”
";
}
}

如果您查看了出现问题的电子邮件的来源,看起来您也应该在循环中创建起始
。虽然您正在关闭循环中的
,但没有创建另一个起始循环,但您没有看到该循环工作得很好。再次感谢你。