Welcome Guest, Not a member yet? Register   Sign In
Error using Email Class
#1

[eluser]brandobandido[/eluser]
Hi CI Masters,

I need your enlightenment here as I'm stumbled again to another CI issue that I can't seem to resolve since last night.

Ok here's the situation. I created a method that's under the Functions library that uses the email class functionality. Below's my code.

Code:
/**
     * Send email function
     *
     * @param array $data
     */

    function sendEmail($data = array())
    {
        $CI =& get_instance();
        $CI->email->from($data['email_from'], $data['email_from_name']);
        $CI->email->to($data['email_to']); // To user
        $CI->email->subject($data['email_subject']);
        $CI->email->message($data['email_message']);
        $CI->email->send();
        // Show the message for debugging
        echo $CI->email->print_debugger();
    }

And in my controller, I called it this way

Code:
$send_email_array = array(
                        'email_from' => '[email protected]',
                        'email_from_name' => 'Test site',
                        'email_to'  => '[email protected]',
                        'email_subject' => 'Subject',
                        'email_message' => 'Message here'
                    );
                    $this->functions->sendEmail($send_email_array);

The Functions library was already auto loaded but when I execute it I get this error

Code:
Fatal error: Call to a member function from() on a non-object in /path/site/system/applications/backend/libraries/Functions.php on line 160

I really don't understand why $CI =& get_instance() is not anymore an object.

Your help would be greatly appreciated as always!

Regards
#2

[eluser]Atharva[/eluser]
It seems you are not loading the email library. Are you auto loading it?
#3

[eluser]brandobandido[/eluser]
[quote author="Atharva" date="1302962204"]It seems you are not loading the email library. Are you auto loading it?[/quote]

Yes I am auto loading it Atharva.
#4

[eluser]InsiteFX[/eluser]
If you are using a Library then you should intialize the CI Super global object like this!
Code:
class Library_name {

    private $CI;

    public function __construct()
    {
        parent::__construct();

        // to access in code use $this->CI
        $this->CI =& get_instance();
    }

}

InsiteFX
#5

[eluser]brandobandido[/eluser]
[quote author="InsiteFX" date="1302983354"]If you are using a Library then you should intialize the CI Super global object like this!
Code:
class Library_name {

    private $CI;

    public function __construct()
    {
        parent::__construct();

        // to access in code use $this->CI
        $this->CI =& get_instance();
    }

}

InsiteFX[/quote]

Hi! Thanks! I will try your suggestion ;-)
#6

[eluser]brandobandido[/eluser]
[quote author="InsiteFX" date="1302983354"]If you are using a Library then you should intialize the CI Super global object like this!
Code:
class Library_name {

    private $CI;

    public function __construct()
    {
        parent::__construct();

        // to access in code use $this->CI
        $this->CI =& get_instance();
    }

}

InsiteFX[/quote]

Hi InsiteFX,

I tried it but still I get the same error. This is really damn because my code worked on some of my controllers.
#7

[eluser]InsiteFX[/eluser]
As Atharva, mentioned above make sure that you are loading the Email Class Library!

Code:
class Library_name {

    private $CI;

    public function __construct()
    {
        parent::__construct();

        // to access in code use $this->CI
        $this->CI =& get_instance();

        $this->CI->load->library('email');
    }

}

InsiteFX
#8

[eluser]brandobandido[/eluser]
[quote author="InsiteFX" date="1302993939"]As Atharva, mentioned above make sure that you are loading the Email Class Library!

Code:
class Library_name {

    private $CI;

    public function __construct()
    {
        parent::__construct();

        // to access in code use $this->CI
        $this->CI =& get_instance();

        $this->CI->load->library('email');
    }

}

InsiteFX[/quote]

I already auto loaded the library as you can see here!

Code:
$autoload['libraries'] = array('template', 'database', 'session', 'email', 'functions', 'form_validation', 'site_settings', 'pagination', 'table', 'texts');
#9

[eluser]InsiteFX[/eluser]
For one you should have your send email in a library not a function!
Code:
// You do not need to assign array here!
// try this!
function sendEmail($data)

InsiteFX
#10

[eluser]Liu Guoqing[/eluser]
Can I help you!!
More Info:
CodeIgniter Dojo Helper
SatSun Studio China




Theme © iAndrew 2016 - Forum software by © MyBB