Welcome to the Cookbook

loading...

5.4.2.2 Setup an email element for the message body

In the app/views/elements/email/ directory you need to set up folders for text and html unless you plan to just send one or the other. In each of these folders you need to create templates for both types of messages referring to the content that you send to the view either by using $this->set() or using the $contents parameter of the send() method. Some simple examples are shown below. It is worthwhile to note that $this->set() should be done before invoking Email's send(), a little break in mindset of the usual CakePHP view conventions. For this example we will call the templates simple_message.ctp

text
 Dear <?php echo $User['first']. ' ' . $User['last'] ?>,
   Thank you for your interest.
  1. Dear <?php echo $User['first']. ' ' . $User['last'] ?>,
  2. Thank you for your interest.
html
 <p>Dear <?php echo $User['first']. ' ' . $User['last'] ?>,<br />
 &nbsp;&nbsp;&nbsp;Thank you for your interest.</p>
  1. <p>Dear <?php echo $User['first']. ' ' . $User['last'] ?>,<br />
  2. &nbsp;&nbsp;&nbsp;Thank you for your interest.</p>