Table of Contents
Sending Email
Three steps to sending HTML emails.
Step 1: Get Component
Get the component email.
Step 2: Create Views
Create /app/views/layouts/email.thtml to hold your layout wrapper. It should look something like this:
<html> <?php echo $content_for_layout; ?> </html>
Create /app/views/yourcontroller/email_to_send.thtml to hold the contents of the email. If you want to use variables you could use something like this:
The value of variable $var_to_email is '<?php echo $var_to_email; ?>'
Step 3: Controller Setup
Add:
var $components = array('Email');
Now, in the controller method you want to email from, add:
$this->set('var_to_email',$some_data_for_email); $this->Email->controller = $this; $this->Email->tpl = 'email_to_send';//name of thtml to include $this->Email->to = 'someone@recipient.com'; $this->Email->from = 'someone@sender.com'; $this->Email->cc = 'someone@copied.com'; $this->Email->bcc = 'someone@blindcopied.com'; $this->Email->subject = 'the subject'; if($this->Email->send()) { $this->set('message','email was sent'); } else { $this->set('message','email could not be sent'); } //the rest of the controller method...