gpt4 book ai didi

email - laravel 5.4 中的邮件发送问题

转载 作者:行者123 更新时间:2023-12-05 04:11:27 26 4
gpt4 key购买 nike

我正在尝试使用 laravel 5.4 发送电子邮件。这是我的 .env

 MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=username@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls

这是我的HomeController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use Mail;
use App\Mail\MyTestMail;

class HomeController extends Controller
{

/**
* Send My Test Mail Example
*
* @return void
*/
public function myTestMail()
{
//echo 'hello';
$myEmail = 'example@gmail.com';
Mail::to($myEmail)->send(new MyTestMail());


dd("Mail Send Successfully");
}

}

但是我得到了这样的错误

Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials r67sm38867592pfb.125 - gsmtp "

at Swift_Transport_AbstractSmtpTransport->_assertResponseCode('535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials r67sm38867592pfb.125 - gsmtp ', array(250)) in AbstractSmtpTransport.php line 281
at Swift_Transport_AbstractSmtpTransport->executeCommand('RSET ', array(250), array()) in EsmtpTransport.php line 270
at Swift_Transport_EsmtpTransport->executeCommand('RSET ', array(250)) in XOAuth2Authenticator.php line 55
at Swift_Transport_Esmtp_Auth_XOAuth2Authenticator->authenticate(object(Swift_SmtpTransport), 'username@gmail.com', 'password') in AuthHandler.php line 176
at Swift_Transport_Esmtp_AuthHandler->afterEhlo(object(Swift_SmtpTransport)) in EsmtpTransport.php line 332

然后我把我的.env文件改为

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=username2@gmail.com
MAIL_PASSWORD=password2
MAIL_ENCRYPTION=tls

然后我重新启动 apache2。但仍然与以前的用户名和密码相同的错误。我不知道为什么会这样?请帮助我。

最佳答案

Google 现在不接受来自安全性较低的应用的登录

您需要授权外部应用程序使用Gmail。

按照接下来的步骤授权制作:

First, go to your Google Account Management page

Under the Security options, click Edit link of Authorising applications & sites

您可以在 Gmail 的设置中允许安全性较低的应用,请转到:

https://www.google.com/settings/security/lesssecureapps

并将“访问安全性较低的应用程序”设置为“已启用”

希望对你有帮助。

关于email - laravel 5.4 中的邮件发送问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42624271/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com