문제

Background

I have a script that sends an email. This email is sent fine. It sends the template, the design is working fine and all the hard coded text is in there.

Problem

Although the mail sends fine, all the variables are missing.

Code

Here is my email template, boardroom_email.ctp in the APP/View/Emails/html/ folder:

<!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 -->

Over here is the function in the BoardroomBookingsController that get's called when a record is successfully saved.

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;
    }
}

Result

This is what the above code sends me:

enter image description here

Question

Obviously I'm missing something small. I had it working at one stage and can't remember that I changed anything, but now, it sends me an email with no data.

What is it that I'm missing?

도움이 되었습니까?

해결책

$this->set('BoardroomBooking', $BoardroomBooking); doesn't work in the new CakeEmailComponent

You need to use:

$this->Email->viewVars(compact('BoardroomBooking'));
//or
$this->Email->viewVars(array('BoardroomBooking' => $BoardroomBooking));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top