使用 error_log() 通过电子邮件发送错误消息

发布于 2024-09-27 00:01:47 字数 410 浏览 0 评论 0原文

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

可能我弄乱了声明内容类型的内容,因为我以纯文本形式收到消息:

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

The php function error_log() let you send logs to email setting the second param to 1. I do that, but i want to dispay message in html. The code looks like this:

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

Probably i mess something declaring the content type, because i get msg in plain text:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

跨年 2024-10-04 00:01:47
error_log("MESSAGE", 1,"[email protected]","From: [email protected]");
error_log("MESSAGE", 1,"[email protected]","From: [email protected]");
甜心小果奶 2024-10-04 00:01:47

您应该阅读 PHP 参考中关于 error_log 的注释,一第一个包含一个示例:

error_log("<html><h2>stuff</h2></html>",1,"[email protected]","subject  :lunch\nContent-Type: text/html; charset=ISO-8859-1");

You should read the comments in the PHP reference for error_log, one of the first ones contains an example :

error_log("<html><h2>stuff</h2></html>",1,"[email protected]","subject  :lunch\nContent-Type: text/html; charset=ISO-8859-1");
棒棒糖 2024-10-04 00:01:47

尝试像这样设置标头:

$headers = "From: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

注意末尾的 content-typemime 标头。

Try to set up your headers like so:

$headers = "From: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

note the content-type and mime headers at the end.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文