Last active
January 1, 2016 13:09
-
-
Save igor822/8149183 to your computer and use it in GitHub Desktop.
Send e-mail with last error occurred
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
<?php | |
function send_error($str = '') { | |
if (getEnvironment() == 'production') { | |
$return = null; | |
// Configuração de dados SMTP, a gosto do programador | |
$Settings = array('auth' => 'login', | |
'ssl'=> 'ssl', | |
'port'=> '465', | |
'username' => '[email protected]', | |
'password' => 'test'); | |
$transport = new Zend_Mail_Transport_Smtp('smtp.domain.com',$Settings); | |
$mail = new Zend_Mail('utf-8'); | |
$mail->setBodyHtml($str); | |
//$mail->setFrom($request["email"], $request['nome']); | |
$mail->setFrom('[email protected]', 'Desenvolvimento'); | |
//se não for passado um email pega o da configuração que foi definido no construct | |
$mail->AddTo('[email protected]',''); | |
$mail->setSubject('Error'); | |
// $return = $mail->send($transport); | |
return $return; | |
} | |
} | |
// Formatação do corpo do e-mail com o erro | |
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; | |
} | |
// Função que pega o erro | |
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