CodeIgniter Forums

Full Version: Fatal error: Call to a member function to() on a non-object in /hermes/bosweb/web200/b2009/ipg.agrobengalcom/shopnodinga
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Sumon[/eluser]
I use same code for sending email in 2 different controller. First one works fine for me but second one shows me the following error.
Quote:Fatal error: Call to a member function to() on a non-object in /hermes/bosweb/web200/b2009/ipg.agrobengalcom/shopnodinga/application/controllers/mist.php on line 114

here is portion of my controller code where i am getting error

Code:
$this->load->library('email');echo $_POST['email'];//Echo shows perfect email address
$this->email->to($_POST['email']); //error indicate this line
$this->email->from('info@shopno-dinga.com','Shopno-Dinga.Com');
$this->email->subject('Update MIST Address Book using this information.');
$message = "test";
$this->email->message($message);
$this->email->send();

what's wrong here ? help me to figure out.

El Forum

[eluser]smilie[/eluser]
I just posted some rubish - do not mind it Smile

Cheers,
Smilie

El Forum

[eluser]Madmartigan1[/eluser]
Well, what happens when you var_dump($this->email) right before the call to send()?

El Forum

[eluser]Sumon[/eluser]
Ops!! program execution stopped and give fatal error at line:
Code:
$this->email->to($_POST['email']);
so program execution doesn't reached at var_dump
Code:
var_dump($this->email)
if i put var_dump befor ->to(....); then it shows
Quote:bool(false)

El Forum

[eluser]srpurdy[/eluser]
try $_REQUEST['email'] instead?

El Forum

[eluser]Madmartigan1[/eluser]
Sounds like the email class isn't loading... Hm...

Something funny going on in that controller? Using modules or anything?

var_dump($this->load->library('email'))?

El Forum

[eluser]Sumon[/eluser]
@srpurdy: Same result for _REQUEST
@Madmar:
i don't use any modules. and it's really surprising. same code works fine in different controller.
when i use var_dump($this->load->library(‘email’)); as
Code:
$this->load->library('email');
var_dump($this->load->library('email')); // it shows NULL
$this->email->to($_REQUEST['email']);
$this->email->from('info@shopno-dinga.com','Shopno-Dinga.Com');
$this->email->subject('Update MIST Address Book using this information.');
$message = "test";
$this->email->message($message);
it shows NULL and error remain same
Fatal error: Call to a member function to() on a non-object in /hermes/bosweb/web200/b2009/ipg.agrobengalcom/shopnodinga/application/controllers/mist.php on line 147

El Forum

[eluser]Madmartigan1[/eluser]
Set logging to "4" in config.php, return your controller to its original state, run the controller, read the log file. There may be something there that will help you figure it out. Do a debug message right before the expected error if you have a hard time following the log.

It's not loading the email class, it's hard to say why without more information.

El Forum

[eluser]Sumon[/eluser]
Smile Works Great your idea.
I found my mistake. Loading email library twice. once from autoload and another from controller. i remove email from autoload and now it works fine.
thanks Madmartigan1

El Forum

[eluser]Madmartigan1[/eluser]
Still it is strange behavior. You should be able to load the class as many times as you want, but you figured out your problem and that's what matters. Now time to get back to work Smile

Update: It's probably better that you don't autoload the email class anyways. It is the #1 biggest library in Codeigniter.