Yii2 SwiftMailer 邮件发送配置与实现
本示例详解了在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 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();
期望上述内容能为使用Yii框架进行PHP开发的读者提供实用帮助。