Swift_TransportException Connection could not be established with host mywebsite.com - laravel

Getting the titled issue with a contact form with my site and sending to a SSL email account on a cpanel godaddy server with Laravel. Has anyone has similar?
Here are the credentials im using:
MAIL_DRIVER=smtp
MAIL_HOST=mywebsite.com
MAIL_PORT=465
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=ssl

For sending emails natively from your own server similar to mail() function use sendmail as driver
MAIL_DRIVER=sendmail
MAIL_HOST=mywebsite.com
MAIL_PORT=465
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=ssl
OR only use mail
MAIL_DRIVER=mail
MAIL_HOST=mywebsite.com
MAIL_PORT=465
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=ssl
Make sure to clear config cache.

Related

Swift_TransportException Connection to ssl://mail.diamonexchange.com:465 Timed Out

Of recent my laravel app keeps timing out on mail cpanel connection
MAIL_MAILER=smtp
MAIL_HOST=mail.******.com
MAIL_PORT=465
MAIL_USERNAME=info#*****.com
MAIL_PASSWORD=**********
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=info#*******.com
MAIL_FROM_NAME="${APP_NAME}"
Here is screenshot of the output

Laravel: office365 connection timeout on aws

Don't know why smtp.office365.com stopped work suddenly on production but works on dev.
Let's see some code:
.env configuration
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=25
MAIL_USERNAME=nao_responda#primorossi.com
MAIL_PASSWORD=********
MAIL_ENCRYPTION=tls
MAIL_SMTPAuth=true
MAIL_FROM_NAME="Grupo Primo Rossi"
MAIL_FROM_ADDRESS=nao_responda#primorossi.com
The Laravel error page:
Swift_TransportException
Connection could not be established with host smtp.office365.com [Connection timed out #110]
The weirdest thing is that this configuration worked ok when I published and stopped working for no reason.
Anyone?
Thanks in advance!
SOLVED!
Chenged the port from 25 to 587
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=nao_responda#primorossi.com
MAIL_PASSWORD=********
MAIL_ENCRYPTION=tls
MAIL_SMTPAuth=true
MAIL_FROM_NAME="Grupo Primo Rossi"
MAIL_FROM_ADDRESS=nao_responda#primorossi.com
Now it is working good!

Google mail of a laravel project not working in cpanel

I was using the following lines in .env file when I was on the localhost and everything was working:
MAIL_MAILER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=myaddress#gmail.com
MAIL_PASSWORD=mypwd
MAIL_ENCRYPTION=ssl
But the moment I hosted the laravel project through cpanel it shows the following error:
Connection could not be established with host smtp.googlemail.com :stream_socket_client(): unable to connect to ssl://smtp.googlemail.com:465 (Network is unreachable)
I then tried with the following .env file, the form sends the mail but I cant actually receive anything:
MAIL_MAILER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465 //tried amending it to 587
MAIL_USERNAME=myaddress#gmail.com
MAIL_PASSWORD=mypwd
MAIL_ENCRYPTION=ssl //tried amending it to tsl when I changed the port to 587 but still same issue
You can’t send mail without enabling less secure apps in google with third-party apps. So let's enable it.
Log in your Gmail account which you want to use for this
Open URL https://myaccount.google.com/lesssecureapps
If it is OFF then make it ON.
Your .env file will then look something like this
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=ENTER_YOUR_EMAIL_ADDRESS(GMAIL)
MAIL_PASSWORD=ENTER_YOUR_GMAIL_PASSWORD
MAIL_ENCRYPTION=ssl
Don't forget to run php artisan config:cache after you make changes in your .env file.

Connection could not be established with host smtp.sendgrid.net :stream_socket_client(): unable to connect to tcp://smtp.sendgrid.net:465

I am trying to send mail using sendgrid in Laravel but it is working on localserver but as i hosted it on server it is giving me following error message:
my mail settings in .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=myusername
MAIL_PASSWORD=XXX
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=info#xyz.com
MAIL_FROM_NAME=xyz
For laravel >= 7
And you are getting this error :
Connection could not be established with host smtp.sendgrid.net :stream_socket_client(): unable to connect to tcp://smtp.sendgrid.net:587 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Simply update your .env file
From:
MAIL_MAILER=smtp
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=your_sendgrid_api_key
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="Your Sender Name"
MAIL_FROM_ADDRESS=info#example.com
To:
MAIL_MAILER=sendMail
MAIL_DRIVER=sendMail
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=your_sendgrid_api_key
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="Your Sender Name"
MAIL_FROM_ADDRESS=info#example.com
Then run this command to make sure .env changes is sync with the code.
php artisan config:cache
Update your env file to:
MAIL_MAILER=sendmail
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=apiPassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=info#example.com
MAIL_FROM_NAME="${APP_NAME}"
Also in your Laravel project under the config folder look for
mail.php
and make changes as follows:
'default' => env('MAIL_MAILER', 'sendmail'),
N/B: SMTP works on localhost and sendmail works on live server.
If you say it works locally but not on production server, try a php artisan config:cache on your web host server. Make sure the ENV configuration is loaded properly (if your host does not support SSH connections, you need to manually update the configuration from ENV into /app/config/* files.
If the issue persists, there are only two possibilities:
Make sure your web host allows outgoing SMTP connections.
Make sure sendgrid.net did not ban your web host outgoing SMTP IP address.
I Experienced this while using a Linode server. Apparently, Some service provider like Linode blocks an SMTP port until you reach out to them via support and ask them for unblock before you can use that PORT and send Email. That was the fix for me
when I migrated to laravel 9, sending with sendgrid didn't work anymore.
The problem was because the new symfony mailer was trying to send with ssl beside tls was set in the config file.
So in the config file, I changed the port from 587 to 465 and it worked again.

Laravel - Connection could not be established with host smtp.googlemail.com :stream_socket_client(): unable to connect

I'm trying to send an email from Gmail using Laravel from localhost. I'm getting this error:
Connection could not be established with host smtp.googlemail.com
:stream_socket_client(): unable to connect to ssl://smtp.googlemail.com:465
(A connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because
connected host has failed to respond.)
My .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=myusername#gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
What is the error? Do i need to change some setting in the server or firewall?
In .env file try the following code:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
mail_username=myusername#gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
In Localhost, edit .env file and paste the following code:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=secret#gmail.com
MAIL_PASSWORD=secret
MAIL_ENCRYPTION=tls
In Server, edit .env file and paste the following code:
Step 1:
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=secret#gmail.com
MAIL_PASSWORD=secret
MAIL_ENCRYPTION=tls
Step 2:
In config/mail.php change the following code:
'default' => env('MAIL_MAILER', 'smtp'),
TO
'default' => env('MAIL_MAILER', 'sendmail'),
Note: Make sure to enable "Less secure app access" in Gmail account.
first of all check your network connectivity and firewall services that are in use.
use your private network for this.
don't use public network.
public network deny the connection.

Resources