Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakeEmail - How do i use it?

In my controller i'm using a email function with the following code:

public function email($mail = null){

    $email = new CakeEmail('default');
    $email->config('default');

    $email->from(array('[email protected]' => 'testing'));
    $email->to('$mail');
    $email->subject('Approved');
    $email->send('Approved');

At the top i have

App::uses('AppController', 'Controller', 'CakeEmail', 'Network/Email');

However, i receive the error Fatal error: Class 'CakeEmail' not found in.

I'm not sure where i have gone wrong. Can anybody please assist?

like image 554
user1192304 Avatar asked Feb 12 '12 17:02

user1192304


3 Answers

You need to change your App::uses and separate the two:

App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');
like image 78
Chuck Burgess Avatar answered Nov 16 '22 20:11

Chuck Burgess


App::uses() does only allow two arguments: $className and $location. You passed 4 arguments, that's why CakeEmail is not loaded.

See http://api20.cakephp.org/class/app#method-Appuses and http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#App::uses for more information

like image 44
nappo Avatar answered Nov 16 '22 18:11

nappo


the documentation is pretty clear about it: http://book.cakephp.org/2.0/en/core-utility-libraries/email.html?highlight=cakeemail#CakeEmail

"First of all, you should ensure the class is loaded"

on a second look: your app::uses() is wrong. check out the way it is documented.

like image 2
mark Avatar answered Nov 16 '22 20:11

mark