预期响应代码 235 但得到代码 535 laravel 使用 office365 smtp 发送电子邮件

Ada*_*att 9 email sendmail office365 laravel

我想在 laravel 应用程序中使用我的 office365 smtp 凭据发送电子邮件。我在我的 .env 文件中对电子邮件设置进行了如下更改:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=info@***.com
MAIL_PASSWORD=*******
MAIL_ENCRYPTION=tls
Run Code Online (Sandbox Code Playgroud)

当我尝试发送电子邮件时,我收到了类似的错误

Failed to authenticate on SMTP server with username \"info@omoyyc.com\" using 2 possible authenticators. Authenticator LOGIN returned Swift_TransportException: Expected response code 235 but got code \"535\", with message \"535 Incorrect authentication data\r\n\"
Run Code Online (Sandbox Code Playgroud)

我的电子邮件发送代码如下

Mail::send(array(), array(), function ($m) use ($templatecontent) {
        $m->from('customerservice@****.com', 'TEST');
        $m->to('test@gmail.com', 'Test')
                ->subject($templatecontent['subject'])
                ->setBody($templatecontent['content'], 'text/html');
    });
Run Code Online (Sandbox Code Playgroud)

谁能指导我是什么问题以及如何解决这个问题?

小智 28

我不知道原因是否与 OP 相同,但我遇到了同样的错误。我通过用双引号括起密码来修复它。

我假设当密码包含特殊字符时解析失败。

  • 我希望能给你100个赞。你救了我的命! (2认同)

小智 9

我遇到过同样的问题。我使用Gmail SMTP启用了不太安全的应用程序禁用了 2 因素身份验证,但没有任何效果。令人惊讶的是,正如 @jessij 提到的,将密码设置在双引号中是有效的

在文件中执行以下操作.env

Replace: MAIL_PASSWORD=yourpassword
With: MAIL_PASSWORD="yourpassword"
Run Code Online (Sandbox Code Playgroud)