To simply put a line in the server error log, use the PHP function error_log (). However, this method will not send an email.
First, to cause an error:
trigger_error("Error message here", E_USER_ERROR);
By default, this will be displayed in the server error log file. See the ErrorLog directive for Apache. To install your own log file:
ini_set('error_log', 'path/to/log/file');
Note that the log file you select must already exist and be a rewritable server process. The easiest way to make a file writable is to make the server owner the owner of the file. (The server user may be nobody, _www, apache, or something else, depending on your OS distribution.)
To send an email, you need to configure your own error handler:
function mail_error($errno, $errstr, $errfile, $errline) { $message = "[Error $errno] $errstr - Error on line $errline in file $errfile"; error_log($message); // writes the error to the log file mail('you@yourdomain.com', 'I have an error', $message); } set_error_handler('mail_error', E_ALL^E_NOTICE);
See the relevant PHP documentation for more information.
Mark Eirich Jul 09 '10 at 5:22 2010-07-09 05:22
source share