5

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>
...
5
  • 1
    I just imaged your mailbox after one error in page with many requests. You don't want to do this. Commented Oct 13, 2010 at 17:04
  • @Pekka: yes i'm talkin about the native one. its not a framework, i'm workin on a standalone loggin class. Commented Oct 13, 2010 at 17:07
  • ah, what do you know, there indeed is one. Sorry, wasn't aware of this Commented Oct 13, 2010 at 17:09
  • @Pekka: error_log() is a native PHP function. php.net/manual/en/function.error-log.php Commented Oct 13, 2010 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. Commented Oct 13, 2010 at 17:12

4 Answers 4

7
error_log("MESSAGE", 1,"[email protected]","From: [email protected]");
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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.

Comments

0

Most likely it does work out of the box already, there is no need to mess with the .ini file.

What's not clear is where is sent this email, in Linux out of the box it's in the built-in mail tool.

This is to be reserved for highly important things only, such as forgery attempts.

<?php error_log('CSRF token validation failed for user: ' . ($_SESSION['username'] . ', Consider a BAN', 1, "[email protected]");

So, after login trough SSH, you'll see:

You have a new mail.

Or type in mail in a terminal.

Postfix will say that the email could not be delivered, but that's fine, as you'll get the mail content.

Thus, to go further and actually send that mail, it's about POSTFIX and SMTP configuration, and not PHP.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.