通过电子邮件发送的HTML表中的PHP MySQL查询结果

时间:2018-07-13 09:51:58

标签: php mysql html-table notifications html-email

有人可以帮我这个忙吗?我已经在php中建立脚本,以通过电子邮件导出mysql搜索查询。一切正常,除了数据已导出并且看起来像字符串,是否可以在基本html表中具有相同的数据,所以看起来更好?请查看收到的图片,该图片在收到电子邮件时如何运行。预先谢谢您:

      getPhotos(): void {
        this.photoService.getPhotos().first()
   .subscribe(response => console.log(response));
      }

实际导出看起来像收到时一样

enter image description here

2 个答案:

答案 0 :(得分:1)

尝试一下:

$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(显示字段名称和值)。

答案 1 :(得分:0)

您必须根据html表或所需的html代码在循环中设置$string变量的格式。因为您的变量是纯字符串,所以它也是电子邮件中的纯字符串。

尝试格式化$string变量。

$string .= "<tr><td>"."Product Name: ".$row->product_name."</td></tr>"."<tr><td>"."Product Code: ".$row->product_code."</td></tr>"."<tr><td>"."Product Color: ".$row->product_color_name."</td></tr>"."<tr><td>"."Product Package/Size: ".$row->package_name."</td></tr>";

还要编辑$message变量

$message = "$e_message

    Dear Admin,<br><br>

    Stock of some or one product(s) is low, see the detail below: <br><br>
    <table>
       $string
    </table>
     $footer";

尝试上面的代码。