Own library to send email codeigniter
I have a problem creating my own librairie to send email. This is my code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Send_email {
private $CI;
public function __construct() {
$this->load->library('email');
$this->CI =& get_instance();
}
public function signup($info, $lang) {
$CI->email->to($info['email']);
...
$CI->email->send();
return TRUE;
}
public function newsletter($info, $lang) {
$CI->email->from('xxx@xxx.om', 'Newsletter');
...
$CI->email->send();
return TRUE;
}
}
/* End of file Send_email.php */
/* Location: ./system/applicat开发者_如何学运维ion/libraries/Send_email.php */
I get the error:
Message: Undefined property: Send_email::$load Filename: libraries/Send_email.php Line Number: 9 Fatal error: Call to a member function library() on a non-object ...
I tried $this->CI->load->library('email');
But I get the error:
Trying to get property of non-object
It seems that the librairie can't be loaded... I would like to load it from the construtor so I don't have to do it in each function. If I load it from each function it works well..
Could you help me? Thanks!
You need to initialize $CI before using it to load the email library...
public function __construct()
{
$this->CI =& get_instance();
$this->CI->load->library('email');
}
精彩评论