I'm trying to send emails from Laravel app that I have in production, but it's not working.
It gives me this error:
Connection could not be established with host smtp.googlemail.com :stream_socket_client(): unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out)
But when I try to send email from localhost it works correctly.
my config mail
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=*********
MAIL_PASSWORD=**********
MAIL_ENCRYPTION=ssl
also email is less secure:on
did you tried it out?
Using gmail smtp via Laravel: Connection could not be established with host smtp.gmail.com [Connection timed out #110]
Also make sure your if your gmail account has 2 factor authentication enabled or not.
If there is any two factor authentication enabled in your account then you can use App specific password from google account page.
There are lots of services you can use like Sendinblue, sendgrid etc.
Related
I have tried send mail by
MAIL_PORT=587 MAIL_ENCRYPTION=tls
AND
MAIL_PORT=465 MAIL_ENCRYPTION=ssl
And I allow the option "less secure app"
But always get this notification: Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to tcp://smtp.gmail.com:587 (Connection timed out)
And same email and password can send mail in other website.
It's same Framework.
but I don't know why that one site can't send email and other can
My Laravel Version is Laravel Framework 8.34.0 and using ubuntu 20.04
How can I fix this problem Thanks everyone
We have changed the email server from a provider to another. The where sending with the old email settings but not with the new ones. I am not sure if it`s laravel server or email server.
I will use here my domain as: example.com
I have changed the new email settings in .env:
MAIL_DRIVER=smtp
MAIL_HOST=server.example.com
MAIL_PORT=465
MAIL_USERNAME=no-reply#example.com
MAIL_PASSWORD=secret
MAIL_ENCRYPTION=ssl
and when we send emails we get this exception in laravel.log
production.ERROR: Connection to tcp://server.example.com:465 Timed Out {"exception":"[object] (Swift_TransportException(code: 0): Connection to tcp://server.example.com:465 Timed Out at /var/www/example.com/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:473, Swift_IoException(code: 0): Connection to tcp://server.example.com:465 Timed Out at /var/www/example.com/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:166)
I have tried also with tls instead of ssl but the same error.
I have configure that email no-replay#example.com in thunderbird with the given settings from the provider and works.
Email settings:
incoming: IMAP server.example.com 993 SSL/TLS Encrypted password
outgoing: SMTP server.example.com 465 SSL/TLS Encrypted password
username (email address) and password.
I am missing something ????
In my case the error was misleading. It's wasn't a timeout but was caused by the wrong encryption setting.
In my case I needed to set MAIL_ENCRYPTION=ssl
If you send your email from an gmail account then try this
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=your_email (like abc#gmail.com)
MAIL_PASSWORD=secret (when you create a app in your google account then get a app secret)
MAIL_ENCRYPTION=ssl
If you do this in your gmail then you can send mail from your gmail account easily
I have a laravel project uploaded on shared hosting via Go Daddy. I find that it's very 'moody, it often stops working.
Often i get time out errors and the erorr below
[2018-07-07n23:22:01] local.ERROR: Failed to authenticate on SMTP server with username "me#ne.org" using 2 possible authenticators {"exception":"[object] (Swift_TransportException(code: 0): Failed to authenticate on SMTP server with username \"x#x.x\" using 2 possible authenticators
I have tried using external smtp services such as mail chip or mailjet and also get errors.
MAIL_DRIVER=smtp
MAIL_HOST=smtp-mail.outlook.com
MAIL_PORT=587
MAIL_USERNAME=username
MAIL_PASSWORD=sdasda
MAIL_ENCRYPTION=TLS
I have even purchased outlook from Godaddy to try solve the issue and not rely on cpanel email.
Could this be becuase i have basic hosting and not business hosting?
Email Sending failed from cpnel but it works fine in my localhost.
Here is my email configuration in .env file.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
It works fine in localhost but not working in cpanel. In cpanel it shows
Connection could not be established with host smtp.gmail.com [Connection refused #111]
How do i solve this?
Problem Solved.
I made the change two things here MAIL_DRIVER and MAIL_PORT.
MAIL_DRIVER=sendmail
MAIL_PORT=587
So, my full code is:
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
It works fine
I know this question has been answered but I have an alternative solution that matches the original description and might help someone. You did not answer Loek's question about whether you run cPanel or not. We run cPanel with lfd/csf firewall, and it has TCP_OUT configuration that lists what outbound ports may be connected to. Port 465 (tls) was not in that list, so we got 'Connection Refused' reports, even trying a low level telnet test on the command line of our VPS server:
$ telnet smtp.gmail.com 465
Trying 74.125.140.109...
telnet: connect to address 74.125.140.109: Connection refused
Trying 74.125.140.108...
telnet: connect to address 74.125.140.108: Connection refused
Trying 2a00:1450:400c:c08::6d...
telnet: connect to address 2a00:1450:400c:c08::6d: Connection refused
The same telnet test worked fine from my local machine.
After adding 465 to the TCP_OUT list:
Load WHM control panel
go to ConfigServer Security & Firewall
go to Firewall Configuration
find TCP_OUT and include 465 (or whatever port you are trying to connect to) to the list
click Change at the bottom of the page, then Restart lfd/csf.
Telnet now succeeds, as does smtpauth mail sending via PHPMailer:
$ telnet smtp.gmail.com 465
Trying 74.125.140.109...
Connected to smtp.gmail.com.
Escape character is '^]'.
(this indicates the socket connection was established.. you probably don't want to actually talk SMTP to Google so hit ctrl-] and type quit and hit enter to close the connection)
Of course this isn't cPanel specific, you may be running another firewall manager that is not allowing outbound connections on the port you're trying to connect to.
After couple of days research. I was having issue of Connection could not be established with host smtp.gmail.com [Connection refused ] because of my godaddy server
As GoDaddy blocks SMTP communication over ports 465 and 587 and possibly 25 originating from your site. They will allow mail flow only through their own SMTP servers.
That was issue in my case. hope it helps someone
For reference check this:
https://pk.godaddy.com/community/Using-WordPress/Connection-Refused-for-GMail-SMTP/td-p/33107
I did face this issue before, I did allow less secure apps from google account manager. And my problem was solved.
It seems like that you too need authorization for extension application in order to use gmail.
You can follow given below steps...
Sign-in into your gmail account.
Access this link to change settings.
Then you have to turn on Allow less secure apps.
After that try again to send email through you host.
I made the nexts steps:
Enter to cPanel of GoDaddy
Go to the option > Email Accounts
Clic in the option > + Create and create a email.
and after change
I resolve this problem by changing the file .env
MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=emailcreated#email.com
MAIL_FROM_NAME="NAME_APP"
I hope that help !!
Hi I setup a contact form for my website with following configuration using Laravel framework
MAIL_DRIVER=smtp
MAIL_HOST=smtp.netregistry.net
MAIL_PORT=465
MAIL_USERNAME= example#domain.com
MAIL_PASSWORD=******
MAIL_ENCRYPTION=ssl
MAIL_FROM= example#domain.com
MAIL_NAME= name
the above config works fine in my localhost, however when I tried in live server it gives me error
Connection could not be established with host smtp.netregistry.net [Connection refused #111]
I tried to fix it by changing mail server to smtp.gmail.com and even tried port 25, 465, 587 for encryption such as ssl, tls, startTLS none of them worked.
So I contacted hosting providers and asked for help and after 12 days of my struggle to get them address my issue finally come up with
our cloud infrastructure does not allow external smtp connections from our hosting. This means that if you are sending emails from your website you will need to use localhost as the smtp host setting.
so now I tried to change my MAIL_HOST to localhost which gave me error
Connection could not be established with host smtp.netregistry.net [Connection refused #0]
and now they were suggesting something wrong with my script. Any suggestions
That is complete BS from your host. First thing, it's common for cloud systems to block OUTGOING SMTP, as it's a spam prevention measure, but your script is fine. Your host may be blocking everything but port 80, which means you can't connect to an SMTP host at all. You may be able to use localhost by not using SMTP at all, and use the builtin mailer(sendmail is common).
Change MAIL_DRIVER=smtp to MAIL_DRIVER=mail to use php's built in mailer. This may solve your problem, if not, then you should seek other hosting arrangements.