Created
August 12, 2013 14:30
-
-
Save igor822/6211305 to your computer and use it in GitHub Desktop.
Error Handler to send e-mail with fatal or parse errors of application
This file contains hidden or 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
register_shutdown_function( "fatal_handler" ); | |
function send_error($str = '') { | |
$Settings = array('auth' => 'login', | |
'ssl'=> 'ssl', | |
'port'=> '465', | |
'username' => 'username', | |
'password' => 'pass'); | |
$transport = new Zend_Mail_Transport_Smtp('smtp.email.com',$Settings); | |
$mail = new Zend_Mail('utf-8'); | |
$mail->setBodyHtml($str); | |
//$mail->setFrom($request["email"], $request['nome']); | |
$mail->setFrom('[email protected]', 'From'); | |
//se não for passado um email pega o da configuração que foi definido no construct | |
$mail->AddTo('[email protected]',''); | |
$mail->setSubject('Erro Elite'); | |
$return = $mail->send($transport); | |
return $return; | |
} | |
function format_error( $errno, $errstr, $errfile, $errline ) { | |
$trace = print_r( debug_backtrace( false ), true ); | |
$content = "<table><thead bgcolor='#c8c8c8'><th>Item</th><th>Description</th></thead><tbody>"; | |
$content .= "<tr valign='top'><td><b>Error</b></td><td><pre>$errstr</pre></td></tr>"; | |
$content .= "<tr valign='top'><td><b>Errno</b></td><td><pre>$errno</pre></td></tr>"; | |
$content .= "<tr valign='top'><td><b>File</b></td><td>$errfile</td></tr>"; | |
$content .= "<tr valign='top'><td><b>Line</b></td><td>$errline</td></tr>"; | |
$content .= "<tr valign='top'><td><b>Trace</b></td><td><pre>$trace</pre></td></tr>"; | |
$content .= '</tbody></table>'; | |
return $content; | |
} | |
function fatal_handler() { | |
$errfile = "unknown file"; | |
$errstr = "shutdown"; | |
$errno = E_CORE_ERROR; | |
$errline = 0; | |
$error = error_get_last(); | |
//error_log(var_export($error, true), 0); | |
if( $error !== NULL) { | |
$errno = $error["type"]; | |
$errfile = $error["file"]; | |
$errline = $error["line"]; | |
$errstr = $error["message"]; | |
if ($errno === E_ERROR || $errno === E_PARSE) send_error(format_error( $errno, $errstr, $errfile, $errline ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment