Difference between #3 and #4 of
How to send emails using SMTP

Revision #4 has been created by Wade Shuler on Apr 15, 2019, 2:57:15 AM with the memo:

The component is mailer, not mail.
« previous (#3) next (#5) »


Title unchanged

How to send emails using SMTP

Category unchanged


Yii version changed


Tags changed

yii2, email, email, yii2,mailer, smtp

Content changed

In your config file just add (it has been already added if you created your project using composer):

'components' => [ ... 'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
Something ike this will work:


'transport' => [
'class' => 'Swift_SmtpTransport',
Use this code for sending emails from your application:


In some cases you might want to use templates for email rendering, so, in that case you just need to do something like:


Yii::$app->mail->compose('@app/mail-templates/email01', [/*Some params for the view */])
Or, if you want to use one template for HTML rendering and another for text, do something like this:


Yii::$app->mail->compose(['html' => '@app/mail-templates/html-email-01', 'text' => '@app/mail-templates/text-email-01'], [/*Some params for the view */])
->setSubject('Advanced email from Yii2-SwiftMailer')
6 0
Viewed: 135 234 times
Version: 2.0
Category: How-tos
Written by: robregonm
Last updated by: Wade Shuler
Created on: Apr 29, 2014
Last updated: 5 years ago
Update Article


View all history