Send errors message via email using error_log()

徘徊边缘 提交于 2019-12-24 03:32:08

问题


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

回答1:


Try to set up your headers like so:

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

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




回答2:


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,"eat@joe.com","subject  :lunch\nContent-Type: text/html; charset=ISO-8859-1");



回答3:


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


来源:https://stackoverflow.com/questions/3926090/send-errors-message-via-email-using-error-log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!