16

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('test@test.com' => '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?

hakre
  • 193,403
  • 52
  • 435
  • 836
user1192304
  • 217
  • 1
  • 3
  • 8

4 Answers4

36

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

App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');
Chuck Burgess
  • 11,600
  • 5
  • 41
  • 74
5

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

nappo
  • 594
  • 3
  • 13
2

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.

mark
  • 21,691
  • 3
  • 49
  • 71
1

You can use the Email component in the controller

public $components = array('Email'); 

public function email(){
  $this->Email->to = 'yourmail@mail.com';  
  $this->Email->subject = 'Subject - ';   
  $this->Email->from = 'sender@mail.com';  
  $this->Email->send('message');
}
Bahdeng
  • 434
  • 8
  • 17
  • This is not advised; the [EmailComponent was deprecated in CakePHP 2](http://book.cakephp.org/2.0/en/core-libraries/components/email.html). – Brad Koch Oct 09 '12 at 19:33