Yii2 配置发送邮件
'components' => [ 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@common/mail', 'useFileTransport' => false, 'transport' => [ 'class' => 'Swift_SmtpTransport', 'host' => 'smtp.163.com', 'username' => '00000@163.com', 'password' => '00000000', 'port' => '25', 'encryption' => 'tls', ], ],
在 config中添加 上述配置
public function actionSendMail() { $content = "<div><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p><p>XXXXXXXXX</p></div>"; \Yii::$app->mailer->compose() ->setFrom('00000@163.com') ->setTo('00000@qq.com') ->setSubject('TEST') ->setTextBody('测试') ->setHtmlBody($content) ->send(); }