背景
我有一个发送电子邮件的脚本。这封电子邮件发送正常。它发送模板,设计工作正常,所有硬编码文本都在那里。
问题
虽然邮件发送正常,但所有变量都丢失了。
代码
以下是我在boardroom_email.ctp
文件夹中的电子邮件模板APP/View/Emails/html/
:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body bgcolor="#CCCCCC">
<table width="800" align="center" bgcolor="#8dc641" cellpadding="0" cellspacing="0">
<tr>
<td>
<!-- Header Image -->
</td>
</tr>
<tr>
<td style="font-family:Arial, Helvetica, sans-serif; font-size:18px; font-weight:bold"><h3 align="center">New Boardroom Booking</h3></td>
</tr>
<tr>
<td style="padding:10px">
<table width="100%" cellpadding="5" cellspacing="5" style="font-family:Arial, Helvetica, sans-serif; font-size:14px" bgcolor="#FFFFFF">
<tr>
<td colspan="2">
The following Boardroom Booking has been made
</td>
</tr>
<tr>
<td width="30%">
<b>Requested By:</b>
</td>
<td width="70%">
<?php echo $BoardroomBooking['BoardroomBooking']['name'] ?>
</td>
</tr>
<!-- File truncated because the rest just repeats the above variable -->
这里是BoardroomBookingsController中的一个函数,它在成功保存记录时被调用。
function _sendNewBoardroomBookingMail($id) {
$BoardroomBooking = $this->BoardroomBooking->read(null,$id);
$this->Email->to = array('Person 1 <person1@mycompany.com>', 'Person 2 <person2@mycompany.com>');
$this->Email->subject = 'A new boardroom booking has been made';
$this->Email->replyTo = 'no-reply@mycompany.com';
$this->Email->from = 'My Company Intraweb <no-reply@mycompany.com>';
$this->Email->template = 'boardroom_email';
$this->Email->sendAs = 'html';
$this->set('BoardroomBooking', $BoardroomBooking);
$this->Email->delivery = 'smtp';
$this->Email->_debug = true;
if ($this->Email->send()) {
return true;
} else {
return false;
}
}
结果
以上代码发送给我:
问题
显然我错过了一些小事。我让它在一个阶段工作,不记得我改变了什么,但现在,它给我发了一封没有数据的电子邮件。
我错过了什么?
答案 0 :(得分:1)
$this->set('BoardroomBooking', $BoardroomBooking);
无法在新的CakeEmailComponent
您需要使用:
$this->Email->viewVars(compact('BoardroomBooking'));
//or
$this->Email->viewVars(array('BoardroomBooking' => $BoardroomBooking));