Sending mail using SMTP authentication in CakePHP
This is an example of sending email using GoogleMail SMTP authentication. You can give a try in CakePHP, this would definitely be helpful.
<?php
class ExampleController extends AppController{
public $name="Example";
public function sendsmtpmail(){
$this->Email->smtpOptions = array(
'port'=>$smtp_settings['email_settings']['smtp_port'],
'timeout'=>$smtp_settings['email_settings']['smtp_timeout'],
'host' => $smtp_settings['email_settings']['smtp_host'],
'username'=>$smtp_settings['email_settings']['smtp_user'],
'password'=>$smtp_settings['email_settings']['smtp_pass'],
);
$this->Email->delivery='smtp';
$this->Email->send = 'debug';
$this->Email->to = 'email@gmail.com';
$this->Email->subject = 'Test Mail';
$this->Email->replyTo = 'mailer@gmail.com';
$this->Email->from = 'WebMailer<mailer@gmail.com>';
$message='This is a test mail sent to check if smtp is working fine or not';
if ( $this->Email->send($message) ) {
$this->Session->setFlash('Simple email sent');
} else {
$this->Session->setFlash('Simple email not sent');
$this->set('smtp_errors', $this->Email->smtpError);
}
}
}
?>
i like this post.thanks to sharing this post
ReplyDelete