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

yii2 sends email (configuring QQ version)

WBOY
WBOYOriginal
2016-07-29 09:13:25915browse
1.在配置文件里面配置
'mailer' => [  
           'class' => 'yii\Swiftmailer\Mailer', //服务器类
            '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']  //邮件里面显示的邮件地址和名称
                ],  
 ]

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

2: You can call

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

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.

Statement:
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]
Previous article:windows nginx +php 配置Next article:Yii PHP框架 版本2