Welcome Guest, Not a member yet? Register   Sign In
Send errors via email
#1

Can anyone tell me how I can get Codeigniter 3 to send details of errors via email. I have found a few examples for older versions none of which work.
Reply
#2

I believe those should still work for CI3. Did it work for you in CI2? If you did not try it in CI2, it's not a problem of CI3, but rather smtp settings. If yes, explain in more detail how it does not work. No errors?
Reply
#3

Not tried in CI2 but others had used it and it worked for them in CI2 but I cant find any code for CI3. I have now tried various examples but none worked so far, the latest code below looks to be o.k. but is giving an error 'Notice: Trying to get property of non-object' when trying to load the config but I cant figure out why.

PHP Code:
class MY_Exceptions extends CI_Exceptions {
    
    protected 
$CI;
    
    public function 
__construct()
    {
            
// Assign the CodeIgniter super-object
            
$this->CI =& get_instance();
    }

    public function 
log_exception($severity$message$filepath$line)
    {

        
// this allows different params for different environments
        
$this->CI->config->load('email_php_errors');

        
// if it's enabled
        
if (config_item('email_php_errors'))
        {
            
// set up email with config values
             
$this->CI->load->library('email');
             
$this->CI->email->from(config_item('php_error_from'));
             
$this->CI->email->to(config_item('php_error_to'));

            
// set up subject
            
$subject config_item('php_error_subject');
            
$subject $this->_replace_short_tags($subject$severity$message$filepath$line);
             
$this->CI->email->subject($subject);

            
// set up content
            
$content config_item('php_error_content');
            
$content $this->_replace_short_tags($content$severity$message$filepath$line);

            
// set message and send
             
$this->CI->email->message($content);
             
$this->CI->email->send();
        }

        
// do the rest of the codeigniter stuff
        
parent::log_exception($severity$message$filepath$line);
    }

    private function 
_replace_short_tags($content$severity$message$filepath$line)
    {
        
$content str_replace('{{severity}}'$severity$content);
        
$content str_replace('{{message}}'$message$content);
        
$content str_replace('{{filepath}}'$filepath$content);
        
$content str_replace('{{line}}'$line$content);

        return 
$content;
    }


Reply




Theme © iAndrew 2016 - Forum software by © MyBB