Having trouble to send email in live server using laravel 5.1 - php

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.

Related

Cannot send email from Laravel app in production

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.

How do I use STARTTLS with swiftmailer in php?

this is my first question here so bare with me.
How do I use STARTTLS with swiftmailer in php?
I am currently on Laravel 7.x running on PHP 7.3.
I need to connect to the Office365 SMTP server, which unforunately only support STARTTLS.
I cannot use another provider than Office365 due to another company infrastructure, so my options are limited.
My problem is that when i give STARTTLS as the mail encryption and attempt to connect to / send mails trough the SMTP server, I recieve the following error:
[2020-06-25 11:15:21] stage.ERROR: Connection could not be established with host smtp.office365.com :stream_socket_client(): unable to connect to starttls://smtp.office365.com:587 (Unable to find the socket transport "starttls" - did you forget to enable it when you configured PHP?) {"userId":1,"exception":"[object] (Swift_TransportException(code: 0): Connection could not be established with host smtp.office365.com :stream_socket_client(): unable to connect to starttls://smtp.office365.com:587 (Unable to find the socket transport "starttls" - did you forget to enable it when you configured PHP?) at /home/forge/censoreddomain.com/releases/20200615132510/src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:269)
My .env config mail section:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=XXXX#XXXX.se
MAIL_PASSWORD=XXXXXXXtXVF
MAIL_ENCRYPTION=starttls
Try to change "MAIL_ENCRYPTION=starttls" to "MAIL_ENCRYPTION=tls"

Send mail thanks to the smtp service of ionos host (1and1)

I have a website hosted by ionos (before it was named 1and1). This website uses the symfony 4 framework. Everything is working properly except for sending emails. I have configure my .env file like this:
MAILER_URL=smtp://contact#mysite.com:password#smtp.ionos.fr:465
But this is not working, and I get this error:
Exception occurred while flushing email queue: Connection could not be established with host smtp.ionos.fr [Connection timed out #110]
I have already tried with the 587 port (TLS), without success. Moreover, I have tried encoding the first # used for the username with %40 to avoid conflict. I think the issue might come from the SMTP configuration.
For those who are struggling, even after reading this:
https://www.ionos.com/help/email-office/general-topics/settings-for-your-email-programs-imap-pop3/
I used the configuration below (with the port 25), and it works!
MAILER_URL=smtp://smtp.ionos.fr:25?auth_mode=login&username=emailAddress&password=myPassword

Connection could not be established with host smtp.gmail.com [Connection refused #111] in laravel 5.6 email send

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 !!

Connection could not be established with host smtp.mailtrap.io [Connection timed out #110]

I want to send email with laravel and I use mailtrap for this
when I tested it in local host this work correctly but in sharing host it shows me this error:
Connection could not be established with host smtp.mailtrap.io [Connection timed out #110]
this is my .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=194f4****98d84
MAIL_PASSWORD=e76fc****f79e7
MAIL_ENCRYPTION=null
when I changed DRIVER value from smtp to sendmail it shows me this error:
"proc_open() has been disabled for security reasons"
Outbound mails could be blocked by your hosting provider. As an example, DigitalOcean blocks the out going emails, for security and spam reasons, and to get it running, you must contact the support team.
I would suggest doing the same with your hosting provider.

Categories