CakeMail无法识别和查看视图功能

时间:2012-04-17 18:19:13

标签: email cakephp-2.0

在我的用户控制器中,我添加了:

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('/');
    }

}

我的email.php配置文件如下:

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'
    );
}

然而,我仍然得到:

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}

为什么?

谢谢!

2 个答案:

答案 0 :(得分:2)

传递

中的单个变量或数组
$email->viewVars($variables);
在您的电子邮件模板中打印

。然后你就可以看到你所有的变量:)

var_dump($this->viewVars);

答案 1 :(得分:1)

易,

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

空了:)

无论如何,谢谢你。