我无法得到电子邮件的内容。未填充$content变量。
$this->request->data['message']来自textarea输入,它允许HTML。
控制器
debug($this->request->data['mensagem']); // Output: <p>\n\ttssseste<\/p>\n
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail();
$email->emailFormat('html');
$email->from(array('noreply@domain.com' => 'System'));
$email->to($this->AuthExtended->user('email'));
$email->subject(__('Sample email'));
$email->template('test_email');
$email->viewVars(array('content' => $this->request->data['mensagem']));
$email->send();查看/电子邮件/html/test_email.ctp
<?php echo $content; ?>我收到电子邮件,但没有内容。如果我将test_email.ctp更改为:
Foo <?php echo $content; ?>我只得到Foo,而不是Foo和$content。
更新
在$email->viewVars(array('content' => $this->request->data['mensagem']));之后,我尝试使用debug($email->viewVars());进行调试,它显示了我的"posted“变量,但是视图中没有任何内容。
array(
'content' => 'foo bar here'
)发布于 2012-11-27 18:54:43
对于发送模板化的电子邮件,请使用以下内容:
$email->模板(‘test_email_view’,'test_email');
这里,test_email_view是查看文件,将其放在app/ view / email /html/test_email_view.ctp中,并将您想要查看的代码放在电子邮件正文消息中。
test_email是布局文件app/View/ layout /Email/html/test_email.ctp,并放置echo $this->fetch('content');
https://stackoverflow.com/questions/13531815
复制相似问题