用户名和密码在yii2中不被接受 [英] Username and Password not accepted in yii2

查看:309
本文介绍了用户名和密码在yii2中不被接受的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有yii2错误,我无法通过电子邮件帐户通过yii发送电子邮件。如果我的密码正确:
这是我的代码:

web.php

 'mailer'=> [
'class'=>'yii\swiftmailer\Mailer',
'transport'= > [
'class'=>'Swift_SmtpTransport',
'host'=>'smtp.gmail.com',
'username'=>'user @ hya。 com.mx',
'password'=>'passwd',
'port'=>'587',
'encryption'=>'tls',
],
],
'log'

控制器。 php

  Yii :: $ app  - >邮件程序 - >撰写()
- > ; setFrom('users@hya.com.mx')
- > setTo('jhon@hya.com.mx')
- > setSubject('Test')
- > setTextBody('纯文本内容)
- > setHtmlBody('It is a test')
- > send();

解决方案

看起来您正在使用Google SMTP服务器。 Google有一项新的安全检查,只允许您发送来自Google应用的电子邮件。如果你使用其他任何你会遇到这样的错误。要解决这个问题,你可以这样做:

使用默认的sendmail函数

 'mailer'=> [
'class'=> 'yii\swiftmailer\Mailer',
'useFileTransport'=>假,
],

我发现第一个解决方案更高效



更改Google设置以允许安全性较低的应用 b
$ b

点击此链接更改您的Gmail设置 https://myaccount.google.com/security


I have a error with yii2, I can't send emails via yii with a email account. If my password is correct :( This is my code:

web.php

'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'transport' => [
            'class'      => 'Swift_SmtpTransport',
            'host'       => 'smtp.gmail.com',
            'username'   => 'user@hya.com.mx',
            'password'   => 'passwd',
            'port'       => '587',
            'encryption' => 'tls',
            ],
        ],
        'log'

Controller.php

Yii::$app -> mailer -> compose()
          -> setFrom('users@hya.com.mx')
          -> setTo('jhon@hya.com.mx')
          -> setSubject('Test')
          -> setTextBody('Plain text content')
          -> setHtmlBody('It is a test')
          -> send();

解决方案

It looks like you are using Google SMTP server. Google has a new security check that only allows you to send emails from google apps. If you are using any other you will run into such errors. To fix this you can do as follows:

Use default sendmail function by having

 'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'useFileTransport' => false,
        ],

I find the first solution more efficient

Change google setting to allow less secure apps

Follow this link to change you gmail settion https://myaccount.google.com/security

这篇关于用户名和密码在yii2中不被接受的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆