Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php//set_error_handler("errorHandler");register_shutdown_function("shutdownHandler");function errorHandler($error_level, $error_message, $error_file, $error_line, $error_context){$error = "lvl: " . $error_level . " | msg:" . $error_message . " | file:" . $error_file . " | ln:" . $error_line;switch ($error_level) {case E_ERROR:case E_CORE_ERROR:case E_COMPILE_ERROR:case E_PARSE:reportwritelog($error, "fatal");break;case E_USER_ERROR:case E_RECOVERABLE_ERROR:writelog($error, "error");break;case E_WARNING:case E_CORE_WARNING:case E_COMPILE_WARNING:case E_USER_WARNING:writelog($error, "warn");break;case E_NOTICE:case E_USER_NOTICE:writelog($error, "info");break;case E_STRICT:writelog($error, "debug");break;default:writelog($error, "warn");}}function shutdownHandler() {$lasterror = error_get_last();switch ($lasterror['type']){case E_ERROR:case E_CORE_ERROR:case E_COMPILE_ERROR:case E_USER_ERROR:case E_RECOVERABLE_ERROR:case E_CORE_WARNING:case E_COMPILE_WARNING:case E_PARSE:$error = "[SHUTDOWN] lvl:" . $lasterror['type'] . " | msg:" . $lasterror['message'] . " | file:" . $lasterror['file'] . " | ln:" . $lasterror['line'];sendmail($error,"fatal");writelog($error, "fatal");}}function writelog($error, $errlvl) {error_log("$error $errlvl");}function reportwritelog($error,$errlvl) {writelog($error,$errlvl);}function sendmail($error,$errlvl) {$to = "anikendra@saholic.com";$from = "anikendra.das@shop2020.in";$subject = "Php fatal error";//begin of HTML message$message = " <html> <body bgcolor='#DCEEFC'> $error </body> </html>";//end of message$headers = "From: $from\r\n";$headers .= "Content-type: text/html\r\n";//options to send to cc+bcc//$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";//$headers .= "Bcc: [email]email@maaking.cXom[/email]";// now lets send the email.mail($to, $subject, $message, $headers); return;$url = 'https://api.sendgrid.com/';$user = 'shop2020';$pass = 'U2/=fP,t';$params = array('api_user' => $user,'api_key' => $pass,'to' => $to,'subject' => $subject,'html' => $message,'text' => $error,'from' => $from);$request = $url.'api/mail.send.json';// Generate curl request$session = curl_init($request);// Tell curl to use HTTP POSTcurl_setopt ($session, CURLOPT_POST, true);// Tell curl that this is the body of the POSTcurl_setopt ($session, CURLOPT_POSTFIELDS, $params);// Tell curl not to return headers, but do return the responsecurl_setopt($session, CURLOPT_HEADER, false);curl_setopt($session, CURLOPT_RETURNTRANSFER, true);// obtain response$response = curl_exec($session);curl_close($session);// print everything outprint_r($response);}