CakeMail doesn't recognize to and viewvars functions

∥☆過路亽.° 提交于 2019-12-11 23:59:27

问题


In my user controller I added:

App::uses('CakeEmail', 'Network/Email');
class UsersController extends AppController { 
      function sign_up() {
        $this->autoRender = false;
        $email = new CakeEmail('default');

        $email->template('sign_up');
        $email->emailFormat('html');
        $email->subject('Addience.com Sign Up');
        $email->to($this->request->query['email']);
        $email->viewVars(array('password' => $this->Password->generatePassword(), 'email' => $this->request->query['email'], 'key' => $this->Password->generateKey()));
        $email->send();
        $this->redirect('/');
    }

}

and my email.php config file looks like:

class EmailConfig {

    public $default = array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'username' => 'xxx@gmail.com',
        'password' => 'xxx',
        'from' => array('support@xxx.com' => 'xxx'),
        'transport' => 'Smtp'
    );
}

However, I still getting:

Notice (8): Undefined index: email [APP\Controller\UsersController.php, line 311]

Notice (8): Undefined index: email [APP\Controller\UsersController.php, line 312]
You need specify one destination on to, cc or bcc.

Error: An Internal Error Has Occurred.
Stack Trace

#0 C:\xampp\htdocs\addience\Controller\UsersController.php(314): CakeEmail->send()
#1 [internal function]: UsersController->sign_up()
#2 C:\xampp\htdocs\cakephp-2.0.6\lib\Cake\Controller\Controller.php(473): ReflectionMethod->invokeArgs(Object(UsersController), Array)
#3 C:\xampp\htdocs\cakephp-2.0.6\lib\Cake\Routing\Dispatcher.php(104): Controller->invokeAction(Object(CakeRequest))
#4 C:\xampp\htdocs\cakephp-2.0.6\lib\Cake\Routing\Dispatcher.php(86): Dispatcher->_invoke(Object(UsersController), Object(CakeRequest), Object(CakeResponse))
#5 C:\xampp\htdocs\addience\webroot\index.php(98): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#6 {main}

Why?

Thank you!


回答1:


pass the single variable or array in

$email->viewVars($variables);

in your email template print this. then you will be able to see all your variables :)

var_dump($this->viewVars);



回答2:


Easy,

$this->request->query['email']

was empty :)

Thank you anyway.



来源:https://stackoverflow.com/questions/10196759/cakemail-doesnt-recognize-to-and-viewvars-functions

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