Home > Backend Development > PHP Tutorial > yii2 sends email (configuring QQ version)

yii2 sends email (configuring QQ version)

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

The above configuration needs to be configured according to your email address.

2: You can call

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

Copyright statement: This article is an original article by the blogger, please correct me if there is anything wrong.

The above introduces how to send emails in yii2 (configuring QQ version), including sending emails, sending emails, and Swift content. I hope it will be helpful to friends who are interested in PHP tutorials.

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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template