How to send Mail using SMTP in Cakephp?

Hi everyone, I am a beginner and have been learning various programming languages like CakePHP, DotNet, Java etc. I faced an issue regarding php programming in which I wanted to learn how we can send mail using SMTP in CakePHP. I have shared many queries in CakePHP developer forum & received fruitful results, so hoping a great support to my query in this community too.

 $Email = new CakeEmail();
 $Email->config('default');

or in your case:

 $Email = new CakeEmail();
 $Email->config('smtp');

or if you want to user a gmail:

 $Email = new CakeEmail();
 $Email->config('gmail');

And then in class EmailConfig

class EmailConfig {

    /*public $default = array(
        'transport' => 'Mail',
        'from' => 'you@localhost',
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    );

    public $smtp = array(
        'transport' => 'Smtp',
        'from' => array('soyazucar@localhost' => 'Test Site'),
        'host' => 'localhost',
        'port' => 25,
        'timeout' => 30,
        'username' => 'user',
        'password' => 'secret',
        'client' => null,
        'log' => false,
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',       
    );*/
    public $gmail = array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'username' => 'guesss@gmail.com',
        'password' => 'password',
        'transport' => 'Smtp'
    );
    /*public $fast = array(
        'from' => 'contreras.amilkar@gmail.com',
        'sender' => null,
        'to' => null,
        'cc' => null,
        'bcc' => null,
        'replyTo' => null,
        'readReceipt' => null,
        'returnPath' => null,
        'messageId' => true,
        'subject' => null,
        'message' => null,
        'headers' => null,
        'viewRender' => null,
        'template' => false,
        'layout' => false,
        'viewVars' => null,
        'attachments' => null,
        'emailFormat' => null,
        'transport' => 'Smtp',
        'host' => 'localhost',
        'port' => 25,
        'timeout' => 30,
        'username' => 'user',
        'password' => 'secret',
        'client' => null,
        'log' => true,
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    );*/

}
1 Like