Home > PHP Framework > YII > body text

What should I do if yii mailer cannot send it?

藏色散人
Release: 2020-04-05 10:35:09
Original
2077 people have browsed it

What should I do if yii mailer cannot send it?

yii mailer What should I do if I can’t send it?

yii2.0 has a problem of not being able to send emails

Related tutorial recommendations:yii framework

yii framework email sending steps:

1. Set up the configuration file, main.php

'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@common/mail',
        'useFileTransport' => false,//这句一定有,false发送邮件,true只是生成邮件在runtime文件夹下,不发邮件
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.exmail.qq.com',  //每种邮箱的host配置不一样
            'username' => '*******@jwsem.com',
            'password' => '********',
            'port' => '465',//企业邮箱,163邮箱服务器端口为: 25
            'encryption' => 'ssl',
        ],
        'messageConfig' => [
            'charset' => 'UTF-8',
            'from' => ['*******@jwsem.com' => '系统']
        ],
    ],
Copy after login

2. Use in the controller

                $mail =\Yii::$app->mailer;
                $mail->useFileTransport = false;//不加此句时,如果收不到邮箱,就是在其他环境设置时是true,所以此处可以加上此句,避免收不到邮箱
                $mail->compose()
                    ->setFrom([*******@jwsem.com'=>'系统'])
                    ->setTo(['*******@jwsem.com','*******@qq.com'])//此处为数组时可以发给多个人
                    ->setSubject('邮箱标题')
                    ->setTextBody('姓名:小花,'  电话:132****8564.')
                    ->send();
Copy after login

Note: During the development of a certain project, this email of mine I couldn't send it. I looked at the configuration in the configuration file and found that 'useFileTransport' => false was correct. Later I found that the configuration in the test environment was 'useFileTransport' => true. At this time, I also added it in the controller. After setting 'useFileTransport' => false, it can be sent normally, but the final reason is to change the configuration in the test environment to false.

The above is the detailed content of What should I do if yii mailer cannot send it?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
yii
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