Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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