PHPIN.NET

 找回密码
 立即注册
查看: 5179|回复: 0

[基础应用] yii2利用swiftmailer发送邮件

[复制链接]

469

主题

31

回帖

5507

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5507
发表于 2016-1-14 22:08:47 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
yii2利用swiftmailer发送邮件

  1. 'mail' => [
  2.         'class' => 'yii\swiftmailer\Mailer',
  3.         'viewPath' => '@backend/mail',
  4.         'useFileTransport' => false,//set this property to false to send mails to real email addresses
  5.         //comment the following array to send mail using php's mail function
  6.         'transport' => [
  7.             'class' => 'Swift_SmtpTransport',
  8.             'host' => 'smtp.gmail.com',
  9.             'username' => 'username@gmail.com',
  10.             'password' => 'password',
  11.             'port' => '587',
  12.             'encryption' => 'tls',
  13.                         ],
  14.     ],
  15.     ],
复制代码

控制器
  1. \Yii::$app->mail->compose('your_view', ['params' => $params])
  2.   ->setFrom([\Yii::$app->params['supportEmail'] => 'Test Mail'])
  3.   ->setTo('to_email@xx.com')
  4.   ->setSubject('This is a test mail ' )
  5.   ->send();
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|PHPIN.NET ( 冀ICP备12000898号-14 )|网站地图

GMT+8, 2024-4-18 09:08

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表