Laravel sendgrid mail not sending - laravel

I'm using sendgrid for sending mails in Laravel in my .env file I have this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_ENCRYPTION=tls
MAIL_USERNAME=my-api-key-username
MAIL_PASSWORD=my-api-key-password
MAIL_FROM_NAME="Company"
MAIL_FROM_ADDRESS=info#mail.nl
However I get this response:
Connection could not be established with host smtp.sendgrid.net [Operation timed out #60]
What am I doing wrong here ?
I have followed the docs but this is not working!
https://sendgrid.com/docs/API_Reference/SMTP_API/integrating_with_the_smtp_api.html
Please help me out.

I was similarly having trouble.
As you noted, you need this in your .env:
MAIL_MAILER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=SG.xxxxxxxxxxxxxxxxxxxxxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
Make sure you're usign the correct .env for whatever environment you're testing (local, staging, production).
Check that you've verified your domain DNS: https://app.sendgrid.com/settings/sender_auth
Also if you've recently created the SendGrid account, I think you're required to click the confirmation email to prove that you own the email address (before sending will work).
See Laravel docs: https://laravel.com/docs/7.x/mail

Related

Failed to send message from Laravel controller

I tried to send an email from a Laravel controller, but it's showing this error. I'm not using a two step verified Gmail account. Most tutorials use the "enable less secure app" settings, but I can't enable that option in my account.
this is my env file
MAIL_MAILER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=******
MAIL_PASSWORD=******
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=********
MAIL_FROM_NAME="${APP_NAME}"
Please use your google app password in MAIL_PASSWORD

Laravel Mail Can't Send

Failed to authenticate on SMTP server with username "#####gmail.com" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted```
i have got this error when sending mail.
My .env configaration is
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=#####gmail.com
MAIL_PASSWORD=######
MAIL_ENCRYPTION=ssl
you need to configure .env like this
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
Don't forget to run php artisan config:cache after you make changes in your .env file.
NOTE:- you need to allow less secure apps from "Google Account" - https://myaccount.google.com/ - Settings - Less secure app access (Turn On)
In your case, please try to enable less secure app.
Turn turn off 2 step verification and enable less secure app (as follows)
go to gmail.com
my account
and enable
Allow less secure apps: ON

How to configure postfix and Laravel on same server

I am developping a complex website but when I try to deploy it I got an error whenever the website needs to send an email (for the email validation system, built-in with Laravel). The error I got is:
[ErrorException (E_NOTICE)] Undefined offset: 3
The exception seems to be thrown from /vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php.
The only changes I made to config/mail.php is to allow self-signed certificates for ssl. My .env file contains these lines:
MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=25
MAIL_USERNAME=myusername //match in real file
MAIL_PASSWORD=mypassword //match in real file
MAIL_FROM_ADDRESS=from#mydomain.stackoverflow
MAIL_FROM_NAME=MyAppName
MAIL_ENCRYPTION=tls
My mail server is on the same server (as you could guess with MAIL_HOST=localhost) and is running postfix with Dovecot. I'm also using a webmail app (roundcube) to use my mail server and it works fine (except for OpenDKIM which doesn't sign outcoming mails).
Do you have any idea where my problem can come from?
EDIT: It works with Mailtrap.io so the problems should come fromp the configuration but I don't know if it comes from my Postfix config or from my Laravel config
EDIT2: I still don't understand why but removing credentials works fine. It works with credentials but only if I remove the MAIL_ENCRYPTION option (setting it to null). So here is the working config I have:
MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_FROM_ADDRESS=from#mydomain.stackoverflow
MAIL_FROM_NAME=MyAppName
MAIL_ENCRYPTION=tls

HostGator, Laravel and Email

I am configuring my Laravel app to send a welcome email, just like Jeffrey Way said at Laracasts and it works fine in Mailtrap. But when I change to HostGator, which I will use in real world, it just not work at all!
Here's some code:
MAIL_DRIVER=sendmail
MAIL_HOST=srv218.prodns.com.br
MAIL_PORT=465
MAIL_USERNAME=automatico#cepcar.com.br
MAIL_PASSWORD=******* <- obviously hidden
MAIL_ENCRYPTION=tls
Have changed the driver to SMTP, encryption to SSL, none but got no success. And the problem is that there are NO ERRORS to debug!
The following changes should solve your issue.
Set a mail from address which is same as MAIL_USERNAME.
Change your mail driver to smtp.
Change mail encryption to ssl.
MAIL_DRIVER=smtp
MAIL_HOST=srv218.prodns.com.br
MAIL_PORT=465
MAIL_USERNAME=automatico#cepcar.com.br
MAIL_PASSWORD=*******
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=automatico#cepcar.com.br
the best solution is to make the following configuration in the .env file in hostgator to be able to send the emails with the corporate emails you have to define your domain on the host
MAIL_HOST= mail.<tu_dominio> => mail.amazonventas.com
MAIL_PORT=465 => estatico
MAIL_MAILER=smtp
MAIL_HOST=mail.amazonventas.com
MAIL_PORT=465
MAIL_USERNAME=**********#amazonventas.com
MAIL_PASSWORD="*********"
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=********#amazonventas.com
MAIL_FROM_NAME="${APP_NAME}"
MAIL_DRIVER=mailgun

forget password not working in laravel 5

I tried to click on link forget password and it says email has been sent but I didn't receive email
I am using gmail smpt in db config
I have already tried to change the setting in .env file but still nothing
This is mail config
MAIL_DRIVER=mail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=username#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
This isn't working it only says email has been sent but I didn't receive mail
I have also allowed in gmail to use Allow less secure apps: ON
so that app can directly send mail
You said you are using smpt driver. but in configuration you have set to mail.
So, you need to set MAIL_DRIVER from mail to smtp as given below:
'MAIL_DRIVER=smtp`.
Which password you are using ? Is that password which you are using to get login to gmail server ?
If yes then go to Myaccount of gmail then go to sign in and security and go to App password and generate password for Mail App and use that password.
May be that works for you. Same is working for me. Also change the following settings in your .env file.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_ENCRYPTION=tls
I changed the value of MAIL_DRIVER from mail to sendmail in the .env file
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=email#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
In account setting of gmail allow unsecured app to send mail works for me

Resources