Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过cakePHP发送邮件_Cakephp_Cakephp 2.3 - Fatal编程技术网

通过cakePHP发送邮件

通过cakePHP发送邮件,cakephp,cakephp-2.3,Cakephp,Cakephp 2.3,我使用以下代码片段发送邮件,但移动到另一台主机会把事情搞砸: public function forgetpwd(){ //code omitted if($this->User->saveField('token_hash',$fu['User']['token_hash'] )){ //============Email================//

我使用以下代码片段发送邮件,但移动到另一台主机会把事情搞砸:

    public function forgetpwd(){    
//code omitted
    if($this->User->saveField('token_hash',$fu['User']['token_hash'] )){

                            //============Email================//
                            /* SMTP Options */
                            $this->Email->smtpOptions = array(
                                    'host' => 'smtp.gmail.com',                             
                                    'port'=>'465',
                                    'transport' => 'Smtp',
                                    'username'=>'email@gmail.com',
                                    'password'=>'secret',
                                    'tls' => true
                            );
                            $this->Email->template = 'resetpw';
                            $this->Email->from    = 'noreply@email.com';
                            $this->Email->to      = $fu['User']['name'].'<'.$fu['User']['email'].'>';
                            $this->Email->subject = __('Recover your password');
                            $this->Email->sendAs = 'both';

                            $this->Email->delivery = 'smtp';
                            $this->set('ms', $ms);
                            $this->Email->send();
                            $this->set('smtp_errors', $this->Email->smtpError);
                            $this->Session->setFlash(__('Check your email to recover your password'));
}

                            //============EndEmail=============//
我确信resetpw.ctp存在于正确的位置

我已经编辑了电子邮件配置,并尝试采用2.3 cakePHP的方式,这就是我最终得到的结果:

            if($this->User->saveField('token_hash',$fu['User']['token_hash'] )){

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

                $Email = new CakeEmail('default');

                $Email->to($fu['User']['email'])
                        ->subject('Reset your password')
                        ->message($key)
                        ->send();

                $this->Session->setFlash(__('Check your mail to reset your password'));

                $this->redirect(array('controller'=>'users','action'=>'reset'));
但现在,当我尝试发送电子邮件时,我收到以下错误:

Call to a member function send() on a non-object
改变

'host' => 'smtp.gmail.com',                             

同时将您的配置信息放在App/config/内的email.php中,如下所述:


路径
/home/public\u html/development/
听起来很像本地调试路径?你确定这是对的吗?另外,请尝试清除缓存文件(app/tmp/cache下的所有内容),同时保留缓存文件夹的目录结构。感谢您的帮助,我已进行了编辑,但现在似乎没有加载电子邮件类。我已经用代码片段更新了这个问题。
'host' => 'smtp.gmail.com',                             
'host' => 'ssl://smtp.gmail.com',