Category Covered

Send mail in cakephp2

If you want to send mail using cakephp 2.x version then this tutorial will help you.

Add the following line

App::uses('CakeEmail', 'Network/Email');

 

Use the following code on your function

 

$email = new CakeEmail();

$email->from(array('noreply@'.env('SERVER_NAME') => 'Sales Tracking Software'));

$email->to($user['User']['username']);

$email->subject('Reset password Mail');

$email->template('recoverpassword');

$email->emailFormat('both');

$email->viewVars(array('password' => $new_passwor));

return $email->send();

 

I have two ctp file named recoverpassword.ctp inside views folder where we will design the email. On that ctp file i can use the variable name "password" as i set this.