您的位置:首页 > 移动开发 > Swift

yii 框架用swiftmailer 发送邮件

2016-07-11 21:46 585 查看

1.先在配置文件中 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,
//'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.163.com',
'username' => 'm18612193548@163.com',
'password' => 'n1234567890',
'port' => '25',
'encryption' => null,

],
'messageConfig'=>[
'charset'=>'UTF-8',
'from'=>['m18612193548@163.com'=>'admin']
],
],

2 。在控制器里加入以下代码进行测试

 

Yii::$app->mailer->compose()
->setFrom('m18612193548@163.com')
->setTo('1297192749@qq.com')
->setSubject('Message subject')
->setTextBody('Plain text content')
->setHtmlBody('<b>傻蛋</b>')
->send();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: