1.在配置文件里面配置
'mailer' => [ 'class' => 'yii\<strong>Swift</strong>mailer\Mailer', //服务器类
'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'] //邮件里面显示的邮件地址和名称 ], ]
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();
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.