Php MySQL查询在HTML表中通过电子邮件发送
有人能帮我吗。我已经用php构建了通过电子邮件导出mysql搜索查询的脚本。一切都很好,除了数据被导出,看起来像字符串,有可能在基本html表中有相同的数据,所以看起来更好吗?请查看在接收电子邮件时它是如何运行的。提前感谢您:Php MySQL查询在HTML表中通过电子邮件发送,php,mysql,html-table,notifications,html-email,Php,Mysql,Html Table,Notifications,Html Email,有人能帮我吗。我已经用php构建了通过电子邮件导出mysql搜索查询的脚本。一切都很好,除了数据被导出,看起来像字符串,有可能在基本html表中有相同的数据,所以看起来更好吗?请查看在接收电子邮件时它是如何运行的。提前感谢您: while ($row = mysql_fetch_object($query)) { $string .= ""."Product Name: ".$row->product_name."".""."Product Code: ".$row->produc
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);
?>
实际导出与收到时的情况类似
必须按照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>";
试试上面的代码。试试这个:
$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列创建一个表列
$string = "<table>";
while ($row = mysql_fetch_object($query)) {
$string .= "<tr>";
foreach($row as $key => $value) {
$string .= "<td>$key: $value</td>";
}
$string .= "</tr>";
}
$string .= "</table>";