Swift_TransportException in StreamBuffer.php line 268: - laravel

When I try to send an email from my laravel site I get this error
Swift_TransportException in StreamBuffer.php line 268: Connection could not be established with host lin01.hkdns.co.za [ #0]
all my details is right. my env
MAIL_DRIVER=smtp
MAIL_HOST=lin01.hkdns.co.za
MAIL_PORT=465
MAIL_USERNAME=info#mysite.co.za
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
In my mail.php
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info#mysite.co.za'),
'name' => env('MAIL_FROM_NAME', 'Info'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
Did I miss something or is this a problem on my server?

Sometime it's possible to be "cache" in the laravel.
Use this command and try again:
php artisan config:clear
If not work, try to restart you xampp.
Another option to check if the problem is with your host or your configuration is to use a Gmail server to send a test email.
Puts this in your .env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=apppassword
MAIL_ENCRYPTION=tls
Create or use any gmail account and enable the less secure apps more information here
first login to your gmail account and under My account > Sign In And
Security > Sign In to google, enable two step verification, then you
can generate app password, and you can use that app password in .env
file.
Your .env file will then look something like this
MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=apppassword
MAIL_ENCRYPTION=tls
Don't forget to run php artisan config:cache after you make changes in
your .env file (or restart your server).
Source here

Related

Laravel 8: Connection could not be established with host smtp.gmail.com

I'm trying to send a simple email from my laravel 8 app using Google SMTP server, but it doesn't work, I'm getting this error:
Swift_TransportException
Connection could not be established with host smtp.gmail.com :stream_socket_client(): SSL:
or
stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
I found many SO post regarding this issue but none of them worked for me, here's a list of what I have tried:
Enabling less secure apps in the google account
using ports 465 and 587
Using smtp.googlemail.com and smtp.gmail.com
Using MAIL_ENCRYPTION=tls and ssl
Changing 'stmp' to 'sendmail'
Blocking switmailer's ssl constraint
Is there something else I can try?
Here's my mail configuration, although I've tried many versions of it:
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=address#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
I had the same problem, I just disabled my antivirus (Avast / windows 10) and its work.
Try this and add the extra auth mode env variable
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=direction#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
MAIL_AUTH_MODE=login
Now go to config/mail.php
and change
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
to
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => env('MAIL_AUTH_MODE'),
],
Finally, it was a problem with Windows. I found some posts pointing that windows just can't execute some mail services. I tried the exact same code in a computer with Ubuntu and it worked at first try.

unable to connect to ssl://smtp.gmail.com:465 (Connection refused) Laravel

Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused)
I tried to send email using laravel but i could not able to send email using godaddy Shared Hosting.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_ENCRYPTION=ssl
Try this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_ENCRYPTION=
Or better:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=secret#gmail.com
MAIL_PASSWORD=secret
MAIL_ENCRYPTION=tls
I have the same issue during development in localhost. I would wanted to test sending of emails from my application using laravel SMTP mailer. Finally the solution was that I added verify_peer and verify_peer_name fields with the value false to SMPTconfig in config/mail.php.
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 465),
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'local_domain' => env('MAIL_EHLO_DOMAIN'),
'verify_peer' => env('MAIL_VALIDATE_CERT', false),
'verify_peer_name' => env('MAIL_VALIDATE_CERT', false)
]
]

Failed to authenticate on SMTP server with username "hello#gmail.com" using 3 possible authenticators

When i run the code i got error "Failed to authenticate on SMTP server with username "hello#gmail.com" using 3 possible authenticators. Authenticator CRAM-MD5 returned Expected response code 235 but got code "535", with message "535 5.7.0 Invalid login or password ". Authenticator LOGIN returned Expected response code 250 but got an empty response. Authenticator PLAIN returned Expected response code 250 but got an empty response."
config/mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
'port' => env('MAIL_PORT', 2525),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#gmail.com'),
'name' => env('MAIL_FROM_NAME', 'Hello'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
'log_channel' => env('MAIL_LOG_CHANNEL'),
];
.env file is
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=hello#gmail.com
MAIL_PASSWORD=****
MAIL_ENCRYPTION=tls
do it like this in your env:
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=***
MAIL_PASSWORD=***
MAIL_ENCRYPTION=tls
Turn on Less secure app access
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=yourmail#gmail.com
MAIL_PASSWORD=yourgmailpassword
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=yourmail#gmail.com
Each port uses a different protocol, errors like the one you had can be caused by the protocol mismatch.
Change your SMTP port to 25 or 465 or 587 or 2525 in .env file,
Save and restart the server by php artisan serve.

Issues with Laravel 5.4 reset password function

I am getting the following error when i reset password in laravel 5.4
Expected response code 250 but got code "530", with message "530-5.5.1 Authentication Required. Learn more at
530 5.5.1 https://support.google.com/mail/?p=WantAuthError s7sm7398940pgb.53 - gsmtp
"
I have correctly entered the username and password aswell as tls and smtp.gmail.com in my env. file.My mail.php file also has the correct credentials.
As for the gmail side of things:My security settings have been set to allow this to work by changing my security settings:Switching on Access for less secure apps.
And my local server,xampp has been sending emails back and forth between all the content management systems ive ever worked on for the past 2 years.I am using laravel 5.4 for the first time.
Heres my .env file
APP_NAME=MyApp
APP_ENV=local
APP_KEY=base64:---------=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=mydb
DB_USERNAME=root
DB_PASSWORD=mypwd
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=myemailpwd
MAIL_ENCRYPTION=tls
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PAYPAL_MODE=
PAYPAL_SANDBOX_CLIENT_ID=
PAYPAL_SANDBOX_SECRET=
PAYPAL_LIVE_CLIENT_ID=
PAYPAL_LIVE_SECRET=
And heres my mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', '587'),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'myemail#gmail.com'),
'name' => env('MAIL_FROM_NAME', 'myname'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/
'username' => env('myemail#gmail.com'),
'password' => env('myemailpwd'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
Change this in your config/mail.php
'username' => env('MAIL_USERNAME', 'fallback email'),
'password' => env('MAIL_PASSWORD', 'fallback password'),
The first param is used for the key as it is defined in your .env, the second one is the default value in case the env('KEY') returns null.
The problem is right now it searches for the key 'myemail#gmail.com' in your .env file, which does not exist, the key name is 'MAIL_USERNAME'.

Laravel Mailtrap Localhost - Error sending mail

I would like to send a emai to a gmail address using Laravel 5.4 and Mailtrap while working on my localhost:8888.
I've got this error Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
I tried
Using different port
php artisan config:clear
What is wrong ?
.env
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=465
MAIL_USERNAME=xxxxx
MAIL_PASSWORD=xxxxx
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=example#example.com
MAIL_FROM_NAME=Leo
config/mail.php
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'username' => env('xxxxx'),
'password' => env('xxxxx'),
I needed to change
'username' => env('xxxxx'),
'password' => env('xxxxx'),
to
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
The below code (in .env file) solved my problem in sending verification
email - Laravel 5.7. No need to change in config/mail.php
MAIL_DRIVER=smtp
MAIL_HOST=mail.somedomain.org
MAIL_PORT=465
MAIL_USERNAME=someone#somedomain.org
MAIL_PASSWORD=your_pwd
MAIL_ENCRYPTION=SSL
MAIL_FROM_ADDRESS=someone#somedomain.org
MAIL_FROM_NAME=SenderName

Resources