预期响应代码 235 但得到代码 535 laravel 使用 office365 smtp 发送电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53298872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Expected response code 235 but got code 535 laravel send email using office365 smtp
提问by Adarsh Bhatt
I want to send email using my office365 smtp credentials in laravel application. i have make changes in my .env file for email settings as below:
我想在 laravel 应用程序中使用我的 office365 smtp 凭据发送电子邮件。我在我的 .env 文件中对电子邮件设置进行了如下更改:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=info@***.com
MAIL_PASSWORD=*******
MAIL_ENCRYPTION=tls
while i am trying to send email i got error like
当我尝试发送电子邮件时,我收到了类似的错误
Failed to authenticate on SMTP server with username \"[email protected]\" 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\"
my email sending code is as below
我的电子邮件发送代码如下
Mail::send(array(), array(), function ($m) use ($templatecontent) {
$m->from('customerservice@****.com', 'TEST');
$m->to('[email protected]', 'Test')
->subject($templatecontent['subject'])
->setBody($templatecontent['content'], 'text/html');
});
Can anyone guide me what is the issue and how to solve this issue?
谁能指导我是什么问题以及如何解决这个问题?
回答by jessij
I don't know if the cause is the same as OP, but I got the same error. I fixed it by enclosing the password with double quotes.
我不知道原因是否与 OP 相同,但我遇到了同样的错误。我通过用双引号括起密码来修复它。
I'm assuming that the parsing fails when the password contains special characters.
我假设当密码包含特殊字符时解析失败。
回答by Adnan Javed
I had the same issue. I used Gmail SMTP, with less secure apps enabled& 2-factor auth disabled, and nothing worked. And surprisingly as @jessij mentioned, setting the password in double-quotes worked.
我遇到过同样的问题。我使用Gmail的SMTP,以不够安全的应用启用和双因素身份验证禁用,并没有什么工作。令人惊讶的是,正如@jessij 提到的,在双引号中设置密码有效。
Do below in .env
file:
在.env
文件中执行以下操作:
Replace: MAIL_PASSWORD=yourpassword
With: MAIL_PASSWORD="yourpassword"
回答by Farhan Yudhi Fatah
my problem is same dude, but my problem has been solved to try it :
我的问题是同样的家伙,但我的问题已经解决了试试看:
- Go to https://myaccount.google.com/security#connectedapps
- Take a look at Security menu -> Apps with account access menu.
- You must turn the option "Allow less secure apps" ON.
- 转到https://myaccount.google.com/security#connectedapps
- 查看安全菜单 -> 带有帐户访问菜单的应用程序。
- 您必须打开“允许安全性较低的应用程序”选项。
If you already followed this step, try again your project. and if it still doesn't work, please continue this steps :
如果您已执行此步骤,请重试您的项目。如果它仍然不起作用,请继续以下步骤:
- Visit https://accounts.google.com/UnlockCaptcha
- Click continue button
Good Luck dude!
哥们好运!