本文实例讲述了Yii2使用swiftmailer发送邮件的方法。分享给大家供大家参考,具体如下:
'mail' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@backend/mail', 'useFileTransport' => false,//set this property to false to send mails to real email addresses //comment the following array to send mail using<strong>*本文来@源gao@daima#com搞(%代@#码@网2</strong><pre>搞代gaodaima码
php’s mail function ‘transport’ => [ ‘class’ => ‘Swift_SmtpTransport’, ‘host’ => ‘smtp.gmail.com’, ‘username’ => ‘[email protected]’, ‘password’ => ‘password’, ‘port’ => ‘587’, ‘encryption’ => ‘tls’, ], ],],
控制器:
Yii::$app->mail->compose('your_view', ['params' => $params]) ->setFrom([\Yii::$app->params['supportEmail'] => 'Test Mail']) ->setTo('[email protected]') ->setSubject('This is a test mail ' ) ->send();
希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。