yii2发送邮件(配置QQ版本)

WBOY
Release: 2016-07-29 09:13:25
Original
911 people have browsed it
1.在配置文件里面配置
Copy after login
'mailer' => [  
           'class' => 'yii\Swiftmailer\Mailer', //服务器类
Copy after login
            'useFileTransport' =>false,//这句一定有,false发送邮件,true只是生成邮件在runtime文件夹下,不发邮件	   
           'transport' => [  
              'class' => 'Swift_SmtpTransport', //使用的类
              'host' => 'smtp.qq.com', //邮箱服务一地址
              'username' => '[email protected]',//邮箱地址,发送的邮箱  
              'password' => '***********',  //自己填写邮箱密码
              'port' => '465',  //服务器端口
              'encryption' => 'ssl', //加密方式 
			  ],
		'messageConfig'=>[  
                 'charset'=>'UTF-8', //编码 
                 'from'=>['[email protected]'=>'admin']  //邮件里面显示的邮件地址和名称
                ],  
 ]
Copy after login

以上配置,需要根据你的邮箱,进行配置。

2:可以调用了

        $fff = Yii::$app->mailer->compose()
		        ->setFrom(['[email protected]'=>'我看你傻了']) //和上面的from字段相对应  可以只写一个
                        ->setTo('[email protected]')
                       ->setSubject('dsfsfsddddddddddddddddddddddddddd')
                       ->setTextBody('sdfffffffffffffffffffffffffffff')
                       ->send();
Copy after login

版权声明:本文为博主原创文章,有不对的地方欢迎指正。

以上就介绍了yii2发送邮件(配置QQ版本),包括了发邮件,发送邮件,Swift方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!