php - 使用 cron 检索 html 格式的电子邮件
问题描述
你好......的同胞们,请跳过所有这些......我在尝试通过我的 cron 输出 html 时遇到了一些困难,我已经检查了对这个问题的其他回复。但是,我似乎无法做到这一点,所以我希望有人可以帮助我。数据正确提取并发送 cron 电子邮件,但我最终得到的是我的数据,其中附加了所有 html 标签。我尝试将 $to 和 $header 移出 while 循环,在 while 循环上方,在 while 循环下方,并尝试使用 while 循环内的所有内容,只有 $message 是对 dtat $row 等的一次调用和然后从循环内回显。我试过两个版本的---
( $headers .= 'Content-type:text/html;charset=iso-8859-1'
. "\r\n";)
和
( $headers .= 'Content-type:text/html;charset=utf-8-1' .
"\r\n";)
所以任何帮助都会很棒!干杯!
$db = new MySQLi('------', '------', '------', '------');
if ($db->connect_error) {
$mese = $db->connect_error; } else {
$sql = "SELECT * FROM table";
$result = $db->query($sql);
while ($row = mysqli_fetch_assoc($result)) {
$to = "some@gmail.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type:text/html;charset=iso-8859-
1'
. "\r\n";
$message = "<html>";
$message .= "<head></head>";
$message .= "<body>";
$message .= '<ul><li>' . $row['item'] .'</li></ul>';
echo $message;
$message .= "</body>";
$message = "</html>";
$from = "somewhere@.someplace.net"; $subject = "checking php
mail";
mail($headers, $to,$subject,$message, $from);
}
}
?>
解决方案
您代码中的所有引号都搞砸了。这可能是原因。
尝试这个:
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html>';
$message .= '<head></head>';
$message .= '<body>';
$message .= '<ul><li>' . $row['item'] .'</li></ul>';
$message .= '</body>';
$message .= '</html>';
推荐阅读
- html - 如何修复在 Chrome 而不是 Safari 中显示的 Sidenav -(Angular 7/Bootstrap 项目)
- android - 如何使用android中的可变实时数据将数据存储库的改造响应中继到视图模型?
- docker - Dockerfile 没有运行所需的 shell 脚本
- reactjs - 如何添加自定义 mapboxgl.js icontrol 以响应组件?
- matplotlib - matplotlib中绘图和比例之间的边距
- jquery - 如何在页面上获取数据表的所有实例
- python - "from __future__ import absolute_import" 不会禁用 Jupyter 笔记本中的相对导入。如何解决?
- html - 独特的 Figcaption 更改网格布局中的图像大小
- database - 在连接字符串中使用变量作为数据库名称的一部分,因此不必为每个用户进行硬编码
- node.js - 在 GitLab CI 中为 Node.js 应用程序构建 Docker 映像