5.4.2.3 Controller
In your controller you need to add the component to your $components array or add a $components array to your controller like:
<?php
var $components = array('Email');
?>
<?phpvar $components = array('Email');?>
In this example we will set up a private method to handle sending the email messages to a user identified by an $id. In our controller (let's use the User controller in this example)
<?php
function _sendNewUserMail($id) {
$User = $this->User->read(null,$id);
$this->Email->to = $User['User']['email'];
$this->Email->bcc = array('secret@example.com');
$this->Email->subject = 'Welcome to our really cool thing';
$this->Email->replyTo = 'support@example.com';
$this->Email->from = 'Cool Web App <app@example.com>';
$this->Email->template = 'simple_message'; // note no '.ctp'
//Send as 'html', 'text' or 'both' (default is 'text')
$this->Email->sendAs = 'both'; // because we like to send pretty mail
//Set view variables as normal
$this->set('User', $User);
//Do not pass any args to send()
$this->Email->send();
}
?>
<?phpfunction _sendNewUserMail($id) {$User = $this->User->read(null,$id);$this->Email->to = $User['User']['email'];$this->Email->bcc = array('secret@example.com');$this->Email->subject = 'Welcome to our really cool thing';$this->Email->replyTo = 'support@example.com';$this->Email->from = 'Cool Web App <app@example.com>';$this->Email->template = 'simple_message'; // note no '.ctp'//Send as 'html', 'text' or 'both' (default is 'text')$this->Email->sendAs = 'both'; // because we like to send pretty mail//Set view variables as normal$this->set('User', $User);//Do not pass any args to send()$this->Email->send();}?>
$this->_sendNewUserMail( $this->User->id );
$this->_sendNewUserMail( $this->User->id );


























