Reputation: 683
In Laravel 7, I want to send email from my application using Office365, tried email password and app password none worked.
MAIL_MAILER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=my-email-here
MAIL_PASSWORD=my-email-password-here
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=my-email-here
MAIL_FROM_NAME="App name"
In the above code MAIL_PASSWORD is my email password not app password this configuration gives me the following error
Failed to authenticate on SMTP server with username "[email protected]" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "451", with message "451 4.7.0 Temporary server error. Please try again later. PRX4 [MRXP264CA0044.FRAP264.PROD.OUTLOOK.COM]
". Authenticator XOAUTH2 returned Expected response code 235 but got code "535", with message "535 5.7.3 Authentication unsuccessful [MRXP264CA0044.FRAP264.PROD.OUTLOOK.COM]
In the second try I put App Password created in office.com as MAIL_PASSWORD value, but I get same error.
after changing the .env I run php artisan cache:clear
and php artisan config:cache
Is there anything I missed, please
Upvotes: 2
Views: 2806
Reputation: 25
you need to put the password in double-quotes.
Replace: MAIL_PASSWORD=yourpassword With: MAIL_PASSWORD="yourpassword"
after changing the .env just run:
php artisan cache:clear
Upvotes: 1
Reputation: 4469
You have to use your email instead of password on MAIL_FROM_ADDRESS like this
MAIL_MAILER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=my-email-here
MAIL_PASSWORD=my-email-password-here
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=my-email-here
MAIL_FROM_NAME="App name"
or you can use smtp-mail.outlook.com as MAIL_HOST
MAIL_MAILER=smtp
MAIL_HOST=smtp-mail.outlook.com
MAIL_PORT=587
MAIL_USERNAME=my-email-here
MAIL_PASSWORD=my-email-password-here
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=my-email-here
MAIL_FROM_NAME="App name"
Upvotes: 0