du7999 2018-08-24 20:07 采纳率: 100%
浏览 86

使用cron检索html格式的电子邮件

Hello fellow citizens of ....oh skip all that... I am experiencing some difficulty trying to output html via my cron and I have checked other responses to this issue. But, I can’t seem to get it right so I’m hoping someone out there can assist me. The data pulls correctly and the cron email sends but what I end up with is my data with all the html tags appended. I have tried moving the $to and $header out of the while loop, above the while loop, below the while loop, and also tried with everything inside the while loop with only the $message being the one call to dtat $row etc and then echo'd that from within the loop. I have tried two versions of ---

( $headers .= 'Content-type:text/html;charset=iso-8859-1' 
. "
";)

and

( $headers .= 'Content-type:text/html;charset=utf-8-1' . 
"
";)

So any assistance would be great! Cheers!

$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' . "
";
        $headers .= 'Content-type:text/html;charset=iso-8859- 
            1'
            . "
";

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

    }
}

?>
  • 写回答

1条回答 默认 最新

  • 普通网友 2018-08-24 20:19
    关注

    All the quotes in your code are messed up. This could be the reason.

    Try this:

    $headers = "MIME-Version: 1.0
    ";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1
    ";
    
    $message =  '<html>';
    $message .= '<head></head>';
    $message .= '<body>';
    $message .= '<ul><li>' . $row['item'] .'</li></ul>';
    $message .= '</body>';
    $message .= '</html>';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题