### 配置
config/web.php
```
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.163.com',
'username' => '15267189004@163.com',
'password' => 'lzj19920310', //授權碼
'port' => '465',
'encryption' => 'ssl',
],
],
```
### 發送
compose()方法包含的視圖文件在mail文件夾內.
```
$mailer = \Yii::$app->mailer->compose('email', ['id' => $id]); //第一個參數是視圖文件名,第二個參數是模板需要的變量
$mailer->setFrom("15267189004@163.com");
$mailer->setTo('649781211@qq.com');
$mailer->setSubject("慕課商城-找回密碼");
$mailer->send(); //返回布爾值
```