Showing posts with label yii2 mailer setup. Show all posts
Showing posts with label yii2 mailer setup. Show all posts

Tuesday, April 24, 2018

Yii2 swiftmailer

Yii2 send email using swiftmailer

Default config in Yii2

'components' => [
                'mailer' => [
                    'class' => 'yii\swiftmailer\Mailer', 
                    'transport' => [
                        'class' => 'Swift_SmtpTransport',
                        'host' => 'localhost',
                        'username' => 'username',
                        'password' => 'password',
                        'port' => '587',
                        'encryption' => 'tls',
                    ],
                ],
            ]

Send email usage:
After mailer component settings, you can use below example to send an email

$mail = Yii::$app->mailer->compose()
    ->setFrom('from@xyz.com')
    ->setTo('to@xyz.com')
    ->setSubject('Subject')
    ->setTextBody('Text')
    ->setHtmlBody('Html data');

     $mail->send();

Recent Update

yii2 session handling

use yii\web\Session; $session = Yii::$app->session; // start session $session->open(); // close session $session->close(); ...

Most Search