【问题标题】:Send errors message via email using error_log()使用 error_log() 通过电子邮件发送错误消息
【发布时间】:2011-04-24 23:24:27
【问题描述】:

php 函数 error_log() 让您将日志发送到电子邮件,将第二个参数设置为 1。我这样做,但我想在 html 中显示消息。代码如下所示:

error_log($this->_errorMsg, 1, ADMIN_MAIL, "Content-Type: text/html; charset=utf8\r\nFrom: ".MAIL_ERR_FROM."\r\nTo: ".ADMIN_MAIL);

可能我在声明内容类型时搞砸了,因为我得到的是纯文本的 msg:

<h1>Website Error</h1>
<b>ERRNO:</b><font color='red'>1</font>
...

【问题讨论】:

  • 我刚刚在页面中出现一个错误并包含许多请求后对您的邮箱进行了映像。你不想这样做。
  • @Pekka:是的,我说的是本地人。它不是一个框架,我正在开发一个独立的登录类。
  • 啊,你知道吗,确实有is one。抱歉,不知道这个
  • @Pekka:error_log() 是一个原生 PHP 函数。 php.net/manual/en/function.error-log.php
  • @Māris: :) 我将使用这个类来完成一项特定的任务,包括 cronjobs。所以我需要知道是否遇到了任何错误,此外我还需要在任何地方用手机访问这些错误日志。

标签: php html-email error-log


【解决方案1】:

您应该阅读 error_log 的 PHP 参考中的 cmets,其中一个包含示例:

error_log("<html><h2>stuff</h2></html>",1,"eat@joe.com","subject  :lunch\nContent-Type: text/html; charset=ISO-8859-1");

【讨论】:

    【解决方案2】:
    error_log("MESSAGE", 1,"email@email.com","From: webmaster@example.com");
    

    【讨论】:

      【解决方案3】:

      尝试像这样设置标题:

      $headers = "From: someone@something.com\r\n";
      $headers .= "MIME-Version: 1.0\r\n";
      $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
      

      注意末尾的 content-typemime 标头。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-20
        • 1970-01-01
        • 2017-01-12
        • 2021-10-25
        相关资源
        最近更新 更多