本文實(shí)例講述了Yii2使用swiftmailer發(fā)送郵件的方法。分享給大家供大家參考,具體如下:
'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 php's mail function
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'username@gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
],
],
控制器:
Yii::$app->mail->compose('your_view', ['params' => $params])
->setFrom([\Yii::$app->params['supportEmail'] => 'Test Mail'])
->setTo('to_email@xx.com')
->setSubject('This is a test mail ' )
->send();
希望本文所述對(duì)大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。