I am trying to setup smtp mail in laravel 9 application but I cant get it to work.
The settings I am using in online smtp tester (which is working good) are:
host:mail.****.**
post:587
Use secured connection: no
Use authentication: yes
login credentials...
in mail.php
file:
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => null,//env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
'verify_peer' => false,
],
and in .env
file:
MAIL_MAILER=smtp
MAIL_HOST=mail.*****.**
MAIL_PORT=587
MAIL_USERNAME=user@******.**
MAIL_PASSWORD=*********
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="user@*****.**"
MAIL_FROM_NAME="${APP_NAME}"
But when I am trying to send the email from my application I get this error:
Failed to authenticate on SMTP server with username "user@*****.**" using the following
authenticators: "CRAM-MD5", "LOGIN", "PLAIN". Authenticator "CRAM-MD5" returned
"Expected response code "235" but got code "535", with message "535 5.7.8 Error:
authentication failed: authentication failure".". Authenticator "LOGIN" returned
"Expected response code "235" but got code "535", with message "535 5.7.8 Error:
authentication failed: authentication failure".". Authenticator "PLAIN" returned
"Expected response code "235" but got code "535", with message "535 5.7.8 Error:
authentication failed: authentication failure".".
My Answer:
There could be several reasons why Laravel failed to authenticate SMTP using the provided authenticators. Here are some common issues and solutions:
1. Incorrect SMTP settings: Double-check the SMTP host, port, username, and password in your Laravel configuration file (config/mail.php). Make sure they are correct and match the settings provided by your email service provider.
2. Firewall or network issues: If your server has a firewall or network restrictions, it may be blocking the connection to the SMTP server. Make sure that the necessary ports (usually 587 or 465 for SMTP) are open and accessible.
3. SSL/TLS configuration: If your SMTP server requires SSL or TLS encryption, make sure that you have configured Laravel to use the correct encryption method. You can set this in the mail.php configuration file under the 'encryption' key.
4. Authentication method: Some SMTP servers may require specific authentication methods such as LOGIN or PLAIN. Check with your email service provider to see which authentication method is required and configure Laravel accordingly.
5. SMTP credentials: Ensure that the username and password you are using to authenticate with the SMTP server are correct. If you are using an app-specific password, make sure it has been generated and entered correctly.
If you have checked all of the above and are still facing authentication issues, you may want to contact your email service provider for further assistance or consider using a different SMTP server.
Rate this post
4 of 5 based on 8220 votesComments