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) »
Changes
Title
unchanged
How to send emails using SMTP
Category
unchanged
How-tos
Yii version
changed
2.0
Tags
changed
yii2, email, email, yii2,mailer, smtp
Content
changed
[...]
Configuration
------------------
In your config file just add (it has been already added if you created your project using composer):
```php
'components' => [
...
'mail
er' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [[...]
Something ike this will work:
```php
'transport' => [
'class' => 'Swift_SmtpTransport',[...]
Use this code for sending emails from your application:
```php
Yii::$app->mail->compose()
->setFrom('somebody@domain.com')[...]
In some cases you might want to use templates for email rendering, so, in that case you just need to do something like:
```php
Yii::$app->mail->compose('@app/mail-templates/email01', [/*Some params for the view */])
->setFrom('from@domain.com')[...]
Or, if you want to use one template for HTML rendering and another for text, do something like this:
```php
Yii::$app->mail->compose(['html' => '@app/mail-templates/html-email-01', 'text' => '@app/mail-templates/text-email-01'], [/*Some params for the view */])
->setFrom('from@domain.com')
->setTo('someemail@server.com')
->setSubject('Advanced email from Yii2-SwiftMailer')
->send();[...]