Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/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
MySQL在phpMail邮件正文中显示结果_Php_Phpmailer - Fatal编程技术网

MySQL在phpMail邮件正文中显示结果

MySQL在phpMail邮件正文中显示结果,php,phpmailer,Php,Phpmailer,我试图通过PHPMailer将MySQL查询的结果回显到电子邮件的正文中,但遇到了一些困难。当我成功地在页面上创建表时,查询工作正常,但似乎无法正确地将表分配给变量 我的代码: $body = '<html> <body> <table> <thead>

我试图通过PHPMailer将MySQL查询的结果回显到电子邮件的正文中,但遇到了一些困难。当我成功地在页面上创建表时,查询工作正常,但似乎无法正确地将表分配给变量

我的代码:

$body = '<html>
                    <body>
                        <table>
                            <thead>
                                <tr>
                                    <th>Food</th>
                                    <th>Quantity</th>
                                    <th>Category</th>
                                <tr>
                            </thead>
                            <tbody>'.
                            while($row = $resultOrderE->fetch(PDO::FETCH_ASSOC)){
                                echo '
                                        <tr>
                                            <td>$row['food']</td>
                                            <td>$row['quantity']</td>
                                            <td>$row['category']</td>
                                        </tr>
                                ';}.'
                            </tbody>
                        </table>
                    </body>
                </html>';

有什么建议吗?谢谢

不能将WHILE循环与字符串相关联

每次循环都必须循环并添加到现有字符串中

$html_string = '<html><body><table><thead><tr><th>Food</th><th>Quantity</th> <th>Category</th><tr></thead><tbody>';

while($row = $resultOrderE->fetch(PDO::FETCH_ASSOC)){
  $html_string .= 
  '<tr><td>'.$row['food'].'</td><td>'.$row['quantity'].'</td><td>'.$row['category'].'</td></tr>';
}

// this will add the closing tags and now html_string has your built email
$html_string .= '</tbody></table></body></html>';
$html_string='FoodQuantity Category';
而($row=$resultOrderE->fetch(PDO::fetch_ASSOC)){
$html_字符串=
“.$row['food'..”.$row['quantity'..”..$row['category'.]。”;
}
//这将添加结束标记,现在html_字符串已生成您的电子邮件
$html_字符串='';

所以
=
是重要的部分,它将一个字符串浓缩到现有字符串的末尾

非常感谢。我不知道,但这是有道理的。
$html_string = '<html><body><table><thead><tr><th>Food</th><th>Quantity</th> <th>Category</th><tr></thead><tbody>';

while($row = $resultOrderE->fetch(PDO::FETCH_ASSOC)){
  $html_string .= 
  '<tr><td>'.$row['food'].'</td><td>'.$row['quantity'].'</td><td>'.$row['category'].'</td></tr>';
}

// this will add the closing tags and now html_string has your built email
$html_string .= '</tbody></table></body></html>';