首页 > 代码库 > Yii2的邮件配置

Yii2的邮件配置

‘components‘ => [  ‘mailer‘ => [            ‘class‘ => ‘yii\swiftmailer\Mailer‘,            ‘useFileTransport‘ =>false,//这句一定有,false发送邮件,true只是生成邮件在runtime文件夹下,不发邮件            ‘transport‘ => [                  ‘class‘ => ‘Swift_SmtpTransport‘,                  ‘host‘ => ‘smtp.163.com‘,  //每种邮箱的host配置不一样                ‘username‘ => ‘-qq32853803-@163.com‘,                  ‘password‘ => ‘.......‘,   邮箱授权码 而非密码                ‘port‘ => ‘25‘,                  ‘encryption‘ => ‘tls‘, // tls  ssl            ],               ‘messageConfig‘=>[                  ‘charset‘=>‘UTF-8‘,                  ‘from‘=>[‘qq328538031@163.com‘=>‘admin‘]               ],          ],   ]        $mail= Yii::$app->mailer->compose();           $mail->setTo(‘cgjs@163.com‘);          $mail->setSubject("邮件测试");          //$mail->setTextBody(‘zheshisha ‘);   //发布纯文字文本        $mail->setHtmlBody("<br>问我我我我我");    //发布可以带html标签的文本//        print_R($mail);//        print_r($mail->send());        if($mail->send())              echo "success";          else              echo "failse";

 

Yii2的邮件配置