邮件发送,但Mail-cakePHP中没有变量

邮件发送,但Mail-cakePHP中没有变量,php,email,cakephp-2.2,Php,Email,Cakephp 2.2,背景 我有一个发送电子邮件的脚本。这封电子邮件发送得很好。它发送模板,设计工作正常,所有硬编码文本都在那里 问题 虽然邮件可以正常发送,但是缺少所有变量 代码 这是我的电子邮件模板,boardroom\u email.ctp,位于APP/View/Emails/html/文件夹中: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-tr

背景

我有一个发送电子邮件的脚本。这封电子邮件发送得很好。它发送模板,设计工作正常,所有硬编码文本都在那里

问题

虽然邮件可以正常发送,但是缺少所有变量

代码

这是我的电子邮件模板,
boardroom\u 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;
    }
}
函数_sendNewBoardroomBookingMail($id){
$BoardroomBooking=$this->BoardroomBooking->read(null,$id);
$this->Email->to=array('Person 1','Person 2');
$this->Email->subject='已预订新的董事会会议室';
$this->Email->replyTo='否-reply@mycompany.com';
$this->Email->from='mycompanyintraweb';
$this->Email->template='boardroom_Email';
$this->Email->sendAs='html';
$this->set('BoardroomBooking',$BoardroomBooking);
$this->Email->delivery='smtp';
$this->Email->_debug=true;
如果($this->Email->send()){
返回true;
}否则{
返回false;
}
}
结果

这是上面的代码发送给我的:

问题

很明显我错过了一些小东西。我在一个阶段就开始工作,不记得我做了什么改变,但现在,它给我发了一封没有数据的电子邮件

我遗漏了什么?

$this->set('BoardroomBooking',$BoardroomBooking')
在新的
CakeEmailComponent

您需要使用:

$this->Email->viewVars(compact('BoardroomBooking'));
//or
$this->Email->viewVars(array('BoardroomBooking' => $BoardroomBooking));

我现在得到一个错误:
调用未定义的方法EmailComponent::viewVars()
您应该使用而不是
EmailComponent