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

时间:2010-10-13 17:00:09

标签: php html-email error-log

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>
...

3 个答案:

答案 0 :(得分:4)

尝试设置标题:

$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标题。

答案 1 :(得分:4)

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

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

答案 2 :(得分:4)

error_log("MESSAGE", 1,"email@email.com","From: webmaster@example.com");
相关问题