Last active
August 29, 2015 14:20
-
-
Save rattrap/07604386924584df2773 to your computer and use it in GitHub Desktop.
Mail PHP error messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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