yii框架中的邮件发送

1.在config中的web.php中加入如下一段话
'components' => [

'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.
    //'viewPath' => 'views\mail',
    'useFileTransport' => false,
    //'class' => 'yii\swiftmailer\Mailer',
    'transport' => [
        'class' => 'Swift_SmtpTransport',
        'host' => 'smtp.163.com',
        'username' => '13020025757@163.com',
        'password' => '*******',
        'port' => '25',
        'encryption' => '',

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

]


2.控制器里调用
$bool= Yii::$app->mailer->compose()
    ->setFrom('13020025757@163.com')//这里必须和web.php里的from相同
    ->setTo('1234567989@qq.com')
    ->setSubject('Message subject')
    ->setTextBody('Plain text content')
    ->setHtmlBody('点我 http://www.setpember.com/yuekao/web/index.php?r=discount/get&d_id='.$arr['dis_id'].'&d_user='.$arr['email']." 领券")
    ->send();

if($bool){
    return $this->success(['discount/index'], '发送成功');
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值