0

次のコード スニペットを使用してメールを送信していましたが、別のホストに移動するとすべてが台無しになりました。

    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=============//

したがって、このビューforgetpwd.ctpがあり、ユーザーは自分の電子メールアドレスを入力するように求められ、電子メールを送信しようとすると、次の2つのエラーが表示されます:

Error: The view for UsersController::forgetpwd() was not found.

Error: Confirm you have created the file: /home/public_html/development/app/View/Emails/text/resetpw.ctp

確かに、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
4

1 に答える 1