Cakephp unable to send email

試著忘記壹切 提交于 2020-01-06 20:12:55

问题


I want to use the cakePHP mailer system, but I am unable to send an email, I get the following error:

 Fatal error: Class 'CakeEmail' not found in D:... on line 100

I have the following defined in my controller:

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

 // In the controller:
 public function search() {
      $email = new CakeEmail();
                    $email->from(array('noreply@assetchase.co.za' => 'Assetchase.co.za'));
                    $email->subject('result notification.');
                    foreach($emails as $value) {
                        $user = $this->User->find("first",array("fields" => array("username"),"conditions" => array("id" => $value)));
                        $email->to($user['User']['username']);
                        $email->send('A new notification, booyah!');
                        // Send an email with the username.
                    }
 }

回答1:


Probably you have to modify App::uses because App::uses() only allows two arguments the class name and its location and you are passing 4 parameter instead

Try this

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

Here is the reference uses

Core Utility Library

Email Basic Usage




回答2:


This is a very common error that developers do at first, Change your App::uses and separate them:

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

Because of the new way cake references the classes.



来源:https://stackoverflow.com/questions/10985532/cakephp-unable-to-send-email

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!