我正在尝试为 HTML 电子邮件模板设置变量,但我似乎无法访问这些变量。当我在模板中回显变量名称时,在发送的电子邮件中会显示一条错误消息“未定义的变量”。在错误描述中,它甚至显示了已设置的变量。
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail();
$Email->from(array('info@example.com' => 'Test'));
$Email->to('myemail@email.com');
$Email->subject('Test email variables');
$Email->template('layout_1');
$Email->emailFormat('html');
$Email->viewVars(array('input_1','test input 1'));
$Email->send();
电子邮件中出现以下错误,我实际上可以看到我设置的“输入 1”变量。
NOTICE (8): UNDEFINED VARIABLE: INPUT_1 [APP/VIEW/EMAILS/HTML/LAYOUT_1.CTP, LINE 44]
CODE CONTEXT
<TR>
<TD CLASS="HEADER-BAR" VALIGN="TOP" STYLE="COLOR: #999; FONT-FAMILY: VERDANA; FONT-SIZE: 10PX; TEXT-TRANSFORM: UPPERCASE; PADDING: 0 20PX; HEIGHT: 15PX;" WIDTH="400"
HEIGHT="15">
<?PHP PRINT_R($INPUT_1); ?>
$VIEWFILE = '/APPLICATIONS/XAMPP/XAMPPFILES/HTDOCS/APP/VIEW/EMAILS/HTML/LAYOUT_1.CTP'
$DATAFORVIEW = ARRAY(
'CONTENT' => '',
(INT) 0 => 'INPUT_1',
(INT) 1 => 'TEST INPUT 1'
)
$CONTENT = ''
INCLUDE - APP/VIEW/EMAILS/HTML/LAYOUT_1.CTP, LINE 44
VIEW::_EVALUATE() - CORE/CAKE/VIEW/VIEW.PHP, LINE 945
VIEW::_RENDER() - CORE/CAKE/VIEW/VIEW.PHP, LINE 907
VIEW::RENDER() - CORE/CAKE/VIEW/VIEW.PHP, LINE 471
CAKEEMAIL::_RENDERTEMPLATES() - CORE/CAKE/NETWORK/EMAIL/CAKEEMAIL.PHP, LINE 1582
CAKEEMAIL::_RENDER() - CORE/CAKE/NETWORK/EMAIL/CAKEEMAIL.PHP, LINE 1448
CAKEEMAIL::SEND() - CORE/CAKE/NETWORK/EMAIL/
CAKEEMAIL.PHP, LINE 1073
TEMPLATESCONTROLLER::SEND_NEWSLETTER() - APP/CONTROLLER/TEMPLATESCONTROLLER.PHP, LINE 110
TEMPLATESCONTROLLER::EDIT() - APP/CONTROLLER/TEMPLATESCONTROLLER.PHP, LINE 194
REFLECTIONMETHOD::INVOKEARGS() - [INTERNAL], LINE ??
CONTROLLER::INVOKEACTION() - CORE/CAKE/CONTROLLER/CONTROLLER.PHP, LINE 486
DISPATCHER::_INVOKE() - CORE/CAKE/ROUTING/DISPATCHER.PHP, LINE 187
DISPATCHER::DISPATCH() - CORE/CAKE/ROUTING/DISPATCHER.PHP, LINE 162
[MAIN] - APP/WEBROOT/INDEX.PHP, LINE 111
我还尝试打印显示的 $dataforview 变量,但我得到了同样的错误。