Welcome Guest, Not a member yet? Register   Sign In
Send error log to email

Until RC versions, I was able to send email from CI_Log file.

PHP Code:
$ci =& get_instance();
$ci->load->library('email'); // Trying to get property of non-object // Call to a member function library() on a non-object 

Now I can't.

I want to send through smtp, email with every error that is writting to log file.

Are you using gmail as service? Because the problem might be there...

GeorgeD - I would like to know more about where you are sending emails form?  I like the idea of sending an email message with an error.

(This post was last modified: 03-20-2015, 01:09 AM by GeorgeD.)

In system/core/Log.php, in function write_log, before last return ( return is_int($result); ). I have written the next code:
PHP Code:
$ci =& get_instance();

$config['protocol']     = 'smtp';
$config['smtp_host']     = '';
$config['smtp_user']     = '';
$config['smtp_pass']     = '';
$config['smtp_port']     = '25';
$config['mailtype']     = 'html';
$config['wordwrap']     = TRUE;
$config['charset']         = 'utf-8';


$ci->email->subject('Error on project ');

I also put an condition for not sending 404 error on mail.

On the begining of project it works, now it doesn't and I didn't changed anything on system folder. 

For line ( $ci->load->library('email'); ) I get:
PHP Code:
NoticeTrying to get property of non-object in system\core\Log.php on line 236

Fatal error
Call to a member function library() on a non-object in system\core\Log.php on line 236 
I checked $ci and is NULL.

Offtopic: I like that CodeIgniter is very simple, fast and easy. But I think that a feature for sending error to email, should get in consideration. I implemented this on every projects, because I want to know in real time if something went wrong with one of my projects. If you have minimum 2 projects is very usefull.

(This post was last modified: 03-20-2015, 05:42 AM by ivantcholakov. Edit Reason: Rever to the original for now: = -> =& )

The error (it could be a new notice or a new warning too) appears before the controller instance has been created. You can deal with this once, there is no need for email sending. For reporting the interesting errors, the email-sender is to be slightly reworked:

$ci =& get_instance();

if (is_object($ci)) {


    // ...

(This post was last modified: 03-20-2015, 05:39 AM by GeorgeD. Edit Reason: UPDATE )

$ci is NULL

With that If I didn't get the error, but also It doesn't send any email.

The problem is that get_instance(); return NULL


If I move get_instance() in __construct() as I saw here: http://www.codeigniter.com/userguide3/ge...asses.html

I receive the following error:
Fatal error: Class 'CI_Controller' not found in system\core\CodeIgniter.php on line 366

It could be that when the error is triggered, it hasn't gotten far enough to load the controller. I'd just use PHPs mail() function directly in there and bypass CI-specific code. Are you altering the /system/Logs.php file directly or extending that core class? It might be helpful for you to post all of your Log code instead of just a snippet.

I am altering CI_Log directly, that why I didn't post all the code. I must send mail through smtp, because on the server the mail() function is disabled.

I don't know how to extend that class, so all the error(including php & db errors) go through extended class.

I know it has been several years since this post.

George D,

Did you ever find a solution to this issue?

Theme © iAndrew 2016 - Forum software by © MyBB