'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";

 

相关文章:

  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
  • 2021-05-03
  • 2021-10-22
  • 2021-12-11
  • 2021-08-07
  • 2021-10-10
猜你喜欢
  • 2021-08-20
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2022-02-07
  • 2021-09-15
相关资源
相似解决方案