Category Covered

send smtp email in cakephp

 

Add email component on your controller

var $components = array('Email');

on your fuction add the following lines to send smtp mail on cakephp

function MyEmail(){
$this->Email->to = 'abc@gmail.com';
$this->Email->subject = 'your mail subject will go here';
$this->Email->from = 'youremail@gmail.com';
$this->Email->template = 'mytemplate'; // in /views/elements/email/text/mytemplate.ctp should be there
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'host' => 'ssl://smtp.gmail.com',
'username'=>'youremail@gmail.com',
'password'=>'password',
);
$this->Email->delivery = 'smtp';
if ($this->Email->send()) {
return true;
} else {
echo $this->Email->smtpError;
}

}