背景
我有一个发送电子邮件的脚本。这封邮件发送得很好。它发送模板,设计工作正常,所有硬编码文本都在那里。
问题
尽管邮件发送正常,但所有变量都丢失了。
代码
这是我的电子邮件模板,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;
}
}
结果
这是上面的代码给我的:
问题
显然我错过了一些小东西。我让它在一个阶段工作,不记得我改变了什么,但现在,它给我发了一封没有数据的电子邮件。
我错过了什么?