Subversion Repositories SmartDukaan

Rev

Rev 11359 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
11359 anikendra 1
<?php
2
register_shutdown_function("shutdownHandler");
3
 
4
function errorHandler($error_level, $error_message, $error_file, $error_line, $error_context)
5
{
6
        $error = "lvl: " . $error_level . " | msg:" . $error_message . " | file:" . $error_file . " | ln:" . $error_line;
7
        switch ($error_level) {
8
            case E_ERROR:
9
            case E_CORE_ERROR:
10
            case E_COMPILE_ERROR:
11
            case E_PARSE:
12
                reportwritelog($error, "fatal");
13
                break;
14
            case E_USER_ERROR:
15
            case E_RECOVERABLE_ERROR:
16
                writelog($error, "error");
17
                break;
18
            case E_WARNING:
19
            case E_CORE_WARNING:
20
            case E_COMPILE_WARNING:
21
            case E_USER_WARNING:
22
                writelog($error, "warn");
23
                break;
24
            case E_NOTICE:
25
            case E_USER_NOTICE:
26
                writelog($error, "info");
27
                break;
28
            case E_STRICT:
29
                writelog($error, "debug");
30
                break;
31
            default:
32
                writelog($error, "warn");
33
        }
34
}
35
 
36
function shutdownHandler() {
37
        $lasterror = error_get_last();
38
        switch ($lasterror['type'])
39
        {
40
            case E_ERROR:
41
            case E_CORE_ERROR:
42
            case E_COMPILE_ERROR:
43
            case E_USER_ERROR:
44
            case E_RECOVERABLE_ERROR:
45
            case E_CORE_WARNING:
46
            case E_COMPILE_WARNING:
47
            case E_PARSE:
48
                $error = "[SHUTDOWN] lvl:" . $lasterror['type'] . " | msg:" . $lasterror['message'] . " | file:" . $lasterror['file'] . " | ln:" . $lasterror['line'];
49
                sendmail($error,"fatal");
50
                writelog($error, "fatal");
51
        }
52
}
53
 
54
function writelog($error, $errlvl) {
55
        error_log("$error $errlvl");
56
}
57
 
58
function reportwritelog($error,$errlvl) {
59
        writelog($error,$errlvl);
60
}
61
 
62
function sendmail($error,$errlvl) {
63
        $to = "anikendra@saholic.com";
64
        $from = "anikendra.das@shop2020.in";
65
        $subject = "Php fatal error";
66
 
67
        //begin of HTML message
68
        $message = " <html> <body bgcolor='#DCEEFC'> $error </body> </html>";
69
        //end of message
70
        $headers  = "From: $from\r\n";
71
        $headers .= "Content-type: text/html\r\n";
72
 
73
        //options to send to cc+bcc
74
        //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
75
        //$headers .= "Bcc: [email]email@maaking.cXom[/email]";
76
 
77
        // now lets send the email.
78
        mail($to, $subject, $message, $headers); return;
79
        $url = 'https://api.sendgrid.com/';
80
        $user = 'shop2020';
81
        $pass = 'U2/=fP,t';
82
 
83
        $params = array(
84
            'api_user'  => $user,
85
            'api_key'   => $pass,
86
            'to'        => $to,
87
            'subject'   => $subject,
88
            'html'      => $message,
89
            'text'      => $error,
90
            'from'      => $from
91
          );
92
 
93
 
94
        $request =  $url.'api/mail.send.json';
95
 
96
        // Generate curl request
97
        $session = curl_init($request);
98
        // Tell curl to use HTTP POST
99
        curl_setopt ($session, CURLOPT_POST, true);
100
        // Tell curl that this is the body of the POST
101
        curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
102
        // Tell curl not to return headers, but do return the response
103
        curl_setopt($session, CURLOPT_HEADER, false);
104
        curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
105
 
106
        // obtain response
107
        $response = curl_exec($session);
108
        curl_close($session);
109
 
110
        // print everything out
11379 anikendra 111
        error_log("[sendgrid] [response] $response");
11359 anikendra 112
}