1
0

send mail on exception

This commit is contained in:
Mike Schwörer 2018-01-28 14:30:19 +01:00
parent cf414a437d
commit aeebdaa71b
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 40 additions and 2 deletions

View File

@ -181,6 +181,7 @@ try {
if (isProd()) if (isProd())
{ {
sendExceptionMail($e);
httpError('500 ', 'Internal server error'); httpError('500 ', 'Internal server error');
} }
else else
@ -191,11 +192,9 @@ try {
} }
//TODO printed books 2 hp
//TODO fast //TODO fast
//TODO gzip (?) //TODO gzip (?)
//TODO better gh widget //TODO better gh widget
//TODO remove db table prefixes //TODO remove db table prefixes
//TODO euler insert+show 32bit | 64bit mode //TODO euler insert+show 32bit | 64bit mode
//TODO send cache header (?) //TODO send cache header (?)
//TODO global uncached error logger -> send by mail

View File

@ -289,4 +289,43 @@ function smart_resize_image($file, $string = null, $width = 0, $height = 0, $pro
} }
return true; return true;
}
function sendMail($subject, $content, $to, $from) {
mail($to, $subject, $content, 'From: ' . $from);
}
function ParamServerOrUndef($idx) {
return isset($_SERVER[$idx]) ? $_SERVER[$idx] : 'NOT_SET';
}
/**
* @param Exception $e
*/
function sendExceptionMail($e)
{
try {
$subject = "Server has encountered an Error at " . date("Y-m-d H:i:s") . "] ";
$content = "";
$content .= 'HTTP_HOST: ' . ParamServerOrUndef('HTTP_HOST') . "\n";
$content .= 'REQUEST_URI: ' . ParamServerOrUndef('REQUEST_URI') . "\n";
$content .= 'TIME: ' . date('Y-m-d H:i:s') . "\n";
$content .= 'REMOTE_ADDR: ' . ParamServerOrUndef('REMOTE_ADDR') . "\n";
$content .= 'HTTP_X_FORWARDED_FOR: ' . ParamServerOrUndef('HTTP_X_FORWARDED_FOR') . "\n";
$content .= 'HTTP_USER_AGENT: ' . ParamServerOrUndef('HTTP_USER_AGENT') . "\n";
$content .= 'MESSAGE:' . "\n" . $e->getMessage() . "\n";
$content .= 'CODE:' . "\n" . $e->getCode() . "\n";
$content .= 'TRACE:' . "\n" . $e->getTraceAsString() . "\n";
$content .= '$_GET:' . "\n" . print_r($_GET, true) . "\n";
$content .= '$_POST:' . "\n" . print_r($_POST, true) . "\n";
$content .= '$_FILES:' . "\n" . print_r($_FILES, true) . "\n";
sendMail($subject, $content, 'virtualadmin@mikescher.de', 'webserver-error@mikescher.com');
}
catch (Exception $e)
{
//
}
} }