php - 通过电子邮件发送 HTML 表中的 PHP MySQL 查询结果
问题描述
有人可以帮我解决这个问题。我已经在 php 中构建了脚本以通过电子邮件导出 mysql 搜索查询。一切工作正常,除了数据被导出并且看起来像字符串,是否可以有相同的数据,但在基本的 html 表中,所以看起来更好?请参阅附加的图像接收电子邮件时它是如何工作的。先感谢您:
while ($row = mysql_fetch_object($query)) {
$string .= ""."Product Name: ".$row->product_name."".""."Product Code: ".$row->product_code."".""."Product Color: ".$row->product_color_name."".""."Product Package/Size: ".$row->package_name."";
}
//email parameters
$to = 'email' . ', '; // note the comma
$to .= '';
$subject = "Low Stock $date_o - $date_a";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Low Stock Notification' . "\r\n";
$message = "$e_message
Dear Admin,<br><br>
Stock of some or one product(s) is low, see the detail below: <br><br>
$string
$footer";
mail($to,$subject,$message,$headers);
?>
实际出口看起来像收到时
解决方案
尝试这个:
$string = "<table>";
while ($row = mysql_fetch_object($query)) {
$string .= "<tr>";
foreach($row as $key => $value) {
$string .= "<td>$key: $value</td>";
}
$string .= "</tr>";
}
$string .= "</table>";
它循环遍历您的 sql 结果,为每个找到的数据库行创建一个表行,并为每个 sql col 创建一个表 col(显示字段名称和值)。
推荐阅读
- reactjs - 切换具有状态依赖的组件
- css - 使用grid而不是flex在最后一行排列一些项目
- javascript - 如何将登录的用户 ID 传递给 Bigcommerce 中的 iframe url
- asp.net-mvc - 如何检查一组值在实体框架中的某个日期/工作日下出现了多少次
- amazon-web-services - 使用 Cognito 防止多个同时登录
- gradle - 如何创建增量构建以从输入文件名派生输出文件名?
- html - Excel VBA 从表中的列表中单击 HTML 元素
- php - PHP:将字符串转换为浮点数(仅当字符串表示浮点数时)
- php - PHP 脚本破坏 HTML 文档的其余部分
- python - 不明白这个 AttributeError: 'function' object has no attribute 'isalpha'