首页 > 解决方案 > 使用 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);

    }
}

?>

标签: phphtmlcron

解决方案


您代码中的所有引号都搞砸了。这可能是原因。

尝试这个:

$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>';

推荐阅读