Expected response code 235 but got code 535 laravel send email using office365 smtp
Asked Answered
O

5

11

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:

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?

Obellia answered 14/11, 2018 at 11:12 Comment(8)
Have you cleared your cache with php artisan cache:clear?Vermifuge
can you please tell me how to run this command on live server using cpanel. I have set following routes in my web.php to clear cache.Route::get('/config-cache', function() { $exitCode = Artisan::call('config:cache'); return '<h1>Clear Config cleared</h1>'; });Obellia
You can run this in the same location as where you run the composer require or composer update commands (I assume local command line?) and then upload all your project files to the server so the updated files are updated on the server tooVermifuge
i am working on live server directly.Obellia
Do you have a terminal/command line interface/open ssh connection to the server? How have you initialized the laravel project?Vermifuge
I have develop whole project in local server and upload it through cpanel.Obellia
Then you should run the command locally and upload the updated project again through cpanelVermifuge
Let us continue this discussion in chat.Obellia
E
39

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.

I'm assuming that the parsing fails when the password contains special characters.

Expel answered 22/4, 2019 at 5:32 Comment(1)
saved my day! thanks :-)Praetorian
F
9

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.

Do below in .env file:

Replace: MAIL_PASSWORD=yourpassword
With: MAIL_PASSWORD="yourpassword"
Flax answered 13/5, 2020 at 23:40 Comment(3)
i still have the same error for office365Granth
@Granth can you please check the logs and confirm if it's "Failed to authenticate on SMTP server" error?Flax
I'm using a business email so I got to know that the sender user seems not Authorised for SMTP, Will check again once get accessGranth
C
2

my problem is same dude, but my problem has been solved to try it :

  1. Go to https://myaccount.google.com/security#connectedapps
  2. Take a look at Security menu -> Apps with account access menu.
  3. You must turn the option "Allow less secure apps" ON.

If you already followed this step, try again your project. and if it still doesn't work, please continue this steps :

  1. Visit https://accounts.google.com/UnlockCaptcha
  2. Click continue button

Good Luck dude!

Claudieclaudina answered 28/4, 2020 at 9:12 Comment(2)
how this is related to office365?Granth
@Granth I am looking at the same thing and maybe you need to check web access over outlook.office365.com if you cannot access it via browser, you may not use it via laravel too. Still looking for a solution.Watersoak
O
2

If your password contains special characters like "john@#3398", put this in " ". Then clear your php artisan cache using

php artisan config:cache

Then start your php artisan serve.

Offish answered 31/7, 2021 at 7:41 Comment(0)
D
1

Interestingly,

php artisan config:clear

wasn't enough for me. I needed to clear app cache, then config cache respectively:

php artisan cache:clear
php artisan config:clear

To understand the issue, I've changed email username and see whether the configurations take effect.

Doyon answered 29/7 at 18:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.