10

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 \"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\"

my email sending code is as below

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');
    });

Can anyone guide me what is the issue and how to solve this issue?

Adarsh Bhatt
  • 548
  • 1
  • 9
  • 30
  • 1
    Have you cleared your cache with `php artisan cache:clear`? – Sven Hakvoort Nov 14 '18 at 11:29
  • 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 '

    Clear Config cleared

    '; });
    – Adarsh Bhatt Nov 14 '18 at 11:58
  • 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 too – Sven Hakvoort Nov 14 '18 at 12:01
  • i am working on live server directly. – Adarsh Bhatt Nov 14 '18 at 12:02
  • Do you have a terminal/command line interface/open ssh connection to the server? How have you initialized the laravel project? – Sven Hakvoort Nov 14 '18 at 12:03
  • I have develop whole project in local server and upload it through cpanel. – Adarsh Bhatt Nov 14 '18 at 12:04
  • Then you should run the command locally and upload the updated project again through cpanel – Sven Hakvoort Nov 14 '18 at 12:04
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/183627/discussion-between-adarsh-bhatt-and-sven-hakvoort). – Adarsh Bhatt Nov 14 '18 at 12:05

4 Answers4

37

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.

jessij
  • 473
  • 4
  • 7
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"
Mostafa Norzade
  • 1,578
  • 5
  • 24
  • 40
Adnan Javed
  • 91
  • 1
  • 1
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!

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.

ParisaN
  • 1,816
  • 2
  • 23
  • 55
Sk Shoyeb
  • 147
  • 1
  • 3