I have a problem with SMTP on my Virtual Private Server with Laravel 9.
Here is an error message:
Unable to connect with STARTTLS: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed"
And my SMTP settings on .env file:
MAIL_MAILER=smtp
MAIL_HOST=smtp.i4ware.fi
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=noreply#i4ware.fi
MAIL_FROM_NAME="${APP_NAME}"
What it the problem. Can anyone help me?
I have Ubuntu Server 20.04 LTS.
You can use cerbot to get ssl certification
https://www.inmotionhosting.com/support/website/ssl/lets-encrypt-ssl-ubuntu-with-certbot/
Or you can diable ssl verification
Editor's note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint such as Gmail, and you'll be vulnerable to a Man-in-the-Middle Attack.
Be sure you fully understand the security issues before using this as a solution.
You can add below code in /config/mail.php
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
Related
I have a CentOS 7 server running lampp, with domain name xxx.example.com. I have successfully config the SSL certificate for https://xxx.example.com.
For email notification purpose, I need to send some emails. My smtp server's domain is smtp.example.com. I could send email in my local environment (Windows 10, xampp) with SSL activated. But when I deploy the site on CentOS, it can't send email with SSL option activated. I have to bypass the SSL verification part to send the email:
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
So, how should I set up my CentOS environment to send email with SSL correctly?
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.
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.
I created an email account on godaddy which works perfectly on server and on localhost. When I did the testing on Linode server using the same email credentials. It did not work and gave 500 Internal Server Error.
Swift_TransportException Connection could not be established with host
sg6plcpnl0067.prod.sin3.secureserver.net [ #0]
Am I missing something?
.env details
MAIL_DRIVER=smtp
MAIL_HOST=sg6plcpnl0067.prod.sin3.secureserver.net
MAIL_PORT=465
MAIL_USERNAME=noreply#myserver.in
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
MAIL_FROM_NAME=myserver
MAIL_FROM_ADDRESS=noreply#myserver.in
I'm migrating a Laravel 5.0 app to 5.4 and am trying to test the mail in my local environment. I've always used Anitix SMTP Imposter for this. Here's what my mail configuration looks like in my .env:
MAIL_DRIVER=smtp
MAIL_HOST=127.0.0.1
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPT=null
This has always worked in all previous versions of Laravel (4, 4.2, 5.0), but suddenly with 5.4 I'm getting the following error:
Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 220 but got code "500", with message "500 Command not recognized
"
I've tried disabling Avast, using alternative programs like Papercut, playing with the config by using SSL or TLS, but I can't figure out what's causing this. Any ideas?
Late answer, but I came here myself running into the same issue.
MailHog does not support TLS encryption. Adding MAIL_ENCRYPTION=null to my .env file fixed my issue.
First try: php artisan config:cache and restart your local server, perhaps Laravel use the old mail data.
For development purpose https://mailtrap.io/ provides you with all the settings that needs to be added in .env file. Eg:
Host: mailtrap.io
Port: 25 or 465 or 2525
Username: cb1d1475bc6cce
Password: 7a330479c15f99
Auth: PLAIN, LOGIN and CRAM-MD5
TLS: Optional
Otherwise for implementation purpose you can get the smtp credentials to be added in .env file from the mail (like gmail n all)
After addition make sure to restart the server
You can use https://mailtrap.io/
it will provide you all necessary details for you to check mail functions in your local machine including username,password,port,host,etc.
if still have same issue issue,
use these details in config/mail.php file in your project instead of using .env file.
return array(
"driver" => "smtp",
"host" => "mailtrap.io",
"port" => 2525,
"username" => "mailtrap.io_your_username",
"password" => "mailtrap.io_your_password",
"sendmail" => "/usr/sbin/sendmail -bs",
"pretend" => false
);
it is work for me.
MAIL_DRIVER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null
I am use a mailhog docker container.
mailhog:
image: mailhog/mailhog:v1.0.0
ports:
- "1025:1025" // smtp
- "8025:8025" // web