Skip to content

Instantly share code, notes, and snippets.

@rattrap
Last active August 29, 2015 14:20
Show Gist options
  • Save rattrap/07604386924584df2773 to your computer and use it in GitHub Desktop.
Save rattrap/07604386924584df2773 to your computer and use it in GitHub Desktop.
Mail PHP error messages
<?php
//
// Custom error handler
//
function new_error_handler($number, $message, $file, $line, $vars) {
$message = "
<p>http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}</p>
<p>An error ({$number}) occurred on line</p>
<strong>{$line}</strong> and in the <strong>file: {$file}.</strong>
<p>{$message}</p>
";
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if(in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1'))) {
die($message);
} else {
error_log($message, 1, 'your.email@domain.com', $headers);
}
}
set_error_handler('new_error_handler');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment