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>
...
Luciano
  • 1,455
  • 8
  • 22
  • 52
  • I just imaged your mailbox after one error in page with many requests. You don't want to do this. – Māris Kiseļovs Oct 13 '10 at 17:04
  • @Pekka: yes i'm talkin about the native one. its not a framework, i'm workin on a standalone loggin class. – Luciano Oct 13 '10 at 17:07
  • ah, what do you know, there indeed [is one](http://de2.php.net/manual/en/function.error-log.php). Sorry, wasn't aware of this – Pekka Oct 13 '10 at 17:09
  • @Pekka: error_log() is a native PHP function. http://php.net/manual/en/function.error-log.php – bcosca Oct 13 '10 at 17:11
  • @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. – Luciano Oct 13 '10 at 17:12

3 Answers3

6
error_log("MESSAGE", 1,"email@email.com","From: webmaster@example.com");
Pedro Luz
  • 2,694
  • 4
  • 44
  • 54
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,"eat@joe.com","subject  :lunch\nContent-Type: text/html; charset=ISO-8859-1");
wimvds
  • 12,790
  • 2
  • 41
  • 42
4

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.

David Titarenco
  • 32,662
  • 13
  • 66
  • 111