Wednesday, October 17, 2012

CakeEmail Error: Call to a member function subject() on a non-object

I was trying this on CakePHP version 2.2.3 Stable. CakePHP has introduced the new CakeEmail replacing the email component. So in order to use it i put this in my controller.

-------------------------------------------------------------
App::uses('CakeEmail', 'Network/Email'); //at the top of page

class MyController extends AppController {

public function test(){
$email = new CakeEmail('smtp');

$result = $email->from('sender@example.com')
->to('you@example.com')
->message('message')
->subject('About')
->send('my message');
->send();

debug($result);
}
-------------------------------------------------------------
When I ran it, it just wouldn't work! As it turns out the problem is with the 'message' function. Some bug is preventing from using it. Just uncomment that and put you message inside send() like this:
        
-------------------------------------------------------------
$email = new CakeEmail('smtp');

$result = $email->from('sender@example.com')
->to('you@example.com')
->message('message')
->subject('About')
//->send('my message'); --> commented out
->send('my message'); --> message was put here
-------------------------------------------------------------
And it works. So here I'm blogging it hoping it would help save someone's day. Cheers


No comments :

About Me

Popular Posts

Designed By Seo Blogger Templates