我试图将MySQL查询的结果回显到通过PHPMailer发送的电子邮件正文中,但是遇到了困难。该查询在我成功创建页面上的表时起作用,但似乎无法正确地将表分配给变量。
我的代码:
$mail->Body=
$html_string = '<html><body><table><thead><tr><th>Food</th><th>Quantity</th> <th>Category</th><tr></thead><tbody>';
$db1 = new mysqli("localhost","dbname","dbname","password");
$sql1 = "select * from tbldatingusermaster order by userid desc";
$result1 = $db1->query($sql1);
while($data1 = $result1->fetch_object()){
$html_string .=
'<tr><td>'.$data1->name.'</td><td>'.$data1->name.'</td><td>'.$data1->name.'</td></tr>';
}
$html_string .= '</tbody></table></body></html>';
;
答案 0 :(得分:0)
您没有将最终字符串添加到$ mail-> Body;
在文件末尾添加它:
$mail->Body = $html_string;
尽管您认为您将其添加为第一行状态
$mail->Body =
...some code here
; //You think this closes the line and assigns value to the $mail->Body
//but that is not true