Reputation: 588
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?
Upvotes: 11
Views: 37993
Reputation: 434
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.
Upvotes: 1
Reputation: 167
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
.
Upvotes: 2
Reputation: 91
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"
Upvotes: 9
Reputation: 385
my problem is same dude, but my problem has been solved to try it :
If you already followed this step, try again your project. and if it still doesn't work, please continue this steps :
Good Luck dude!
Upvotes: 2
Reputation: 493
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.
Upvotes: 39