Send errors message via email using error_log()
Asked Answered
B

3

4

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>
...
Butyl answered 13/10, 2010 at 17:0 Comment(5)
I just imaged your mailbox after one error in page with many requests. You don't want to do this.Lail
@Pekka: yes i'm talkin about the native one. its not a framework, i'm workin on a standalone loggin class.Butyl
ah, what do you know, there indeed is one. Sorry, wasn't aware of thisDisabled
@Pekka: error_log() is a native PHP function. php.net/manual/en/function.error-log.phpJoslyn
@Māris: :) I'm gonna use this class for a particular task, with cronjobs. So i need to know if any errors has encountered, besides i need to access these error logs with my phone everywhere.Butyl
M
4

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.

Menton answered 13/10, 2010 at 17:12 Comment(0)
M
6
error_log("MESSAGE", 1,"[email protected]","From: [email protected]");
Mitran answered 12/12, 2013 at 22:41 Comment(0)
T
5

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");
Teuton answered 13/10, 2010 at 17:13 Comment(0)
M
4

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.

Menton answered 13/10, 2010 at 17:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.