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}

为什么?

谢谢!

4

2 回答 2

2

传入单个变量或数组

$email->viewVars($variables);

在您的电子邮件模板中打印此内容。那么您将能够看到所有变量:)

var_dump($this->viewVars);
于 2013-10-31T11:25:48.250 回答
1

简单的,

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

是空的:)

还是非常感谢。

于 2012-04-17T18:58:14.420 回答