Viewed   220 times

I am trying to send email from my laravel 5.1 system. I can send emails from my localhost and unable to send from the server. See my email configuration settings in .env file,

MAIL_DRIVER=smtp
MAIL_HOST= smtp.gmail.com
MAIL_PORT= 587
MAIL_USERNAME= username***@gmail.com
MAIL_PASSWORD= *********
MAIL_ENCRYPTION=tls

This configuration only work on my localhost. On server I am getting this error,

Swift_TransportException in StreamBuffer.php line 268:
Connection could not be established with host smtp.gmail.com [Network is unreachable #101]

I also try with changing MAIL_PORT from 587 to 465 and MAIL_ENCRYPTION from tls to ssl. But I am geeitng the same error. How can I fix this issue?

 Answers

4

I solved my problem in cpanel using the code:

change MAIL_DRIVER=smtp to MAIL_DRIVER=sendmail in ".env" file
Saturday, August 6, 2022
 
akf
 
akf
1

1: Either you must allow less secure apps or use app password by enabling 2 step verification on your gmail acc.

2: Disable any antivirus on your machine(this is something no one will tell u but is necessary in many cases).

3: Don't forget to clear your cache (sometimes it don't take updated content from .env file)

4: You don't need to change anything in Mailer inside config directory(not recommended), you should use env variables

Sunday, August 21, 2022
 
asnr
 
2

Update my driver line to

MAIL_DRIVER=sendmail

It works on the first try.

Final .env file should look like this

MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=*****
Friday, October 28, 2022
 
4

Make sure you install Guzzle to your project by adding the following line to your composer.json file:

"guzzlehttp/guzzle": "~5.3|~6.0"

and editing your .env file with real email-id and password. Also, enable, less secure apps for that email-id as told by @Bharat Geleda

then your above code will run properly.

Tuesday, November 8, 2022
 
wombatz
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :