Email is the important functionality in web applications. CakeEmail is a class used to send Email from your application.
By using CakeEmail class you can send email any where in your application. When we use CakeEmail in our application, it replaces Email component.
To send Email from localhost you need to follow some steps written below:
Step 1: First open your localhost php.ini file. php.ini is present in your server’s PHP directory. In this file add below written code and then save php.ini file.
extension=php_openssl.dll
Step 2: Next configure your CakePHP email component. To configure CakePHP email component add following lines of code in /app/Config/email.php
<?php
class EmailConfig
{
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'youremail@gmail.com',
'password' => 'YourPassword',
'transport' => 'Smtp'
);
}
?>
This will override your CakeEmail’s email component.
Step 3: Next make your own function in Your Controller file like
<?php
public function send_mail($receiver = null, $name = null, $pass = null)
{
$confirmation_link = "http://" . $_SERVER['HTTP_HOST'] . $this->webroot . "users/login/";
$message = 'Hi,' . $name . ', Your Password is: ' . $pass;
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('gmail');
$email->from('youremail@gmail.com');
$email->to($receiver);
$email->subject('Mail Confirmation');
$email->send($message . " " . $confirmation_link);
}
?>
0 Comment(s)