Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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.gmail.com [ #0]
I'm using ssl with port 465. I also tried 587 but it didn't work.
I also tried
this
but it didn't work. I found a lot of people suffering from the same problems, but the solutions I found didn't work.
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 GitHub or some other remote Git host), 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.
In Laravel project directory, edit
config/mail.php
and add the following:
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
It worked for me.
Fyi, my SMTP settings are:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=[Full Gmail Address]
MAIL_PASSWORD=[Google App Password obtained after two step verification on Google Account Page]
MAIL_ENCRYPTION=ssl
–
–
In your .env file you will need to set the email address and password of your email account:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=testpassword
and in mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => '[email protected]', 'name' => 'Your Title'],
'encryption' => 'tls',
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
and clear the config cache with:
php artisan config:cache
–
in localhost you can set your MAIL_DRIVER=smtp but on real server like cpanel you must to set MAIL_DRIVER=sendmail and edit your config/mail.php
'default' => env('MAIL_MAILER', 'sendmail'),
but its not good idea because after you send mail on google you get error on gmail like this :
Be careful with this message
Gmail could not verify that it actually came from [email protected]. Avoid clicking links, downloading attachments, or replying with personal information.