5

I'm getting an error in mailhog while sending an email to new user for creating password.

Error:

Connection could not be established with host mailhog :stream_socket_client(): php_network_getaddresses: getaddrinfo failed: No such host is known.

.env config:

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="dev@example.com"
MAIL_FROM_NAME="${APP_NAME}"
Pathros
  • 10,042
  • 20
  • 90
  • 156
vishakha saxena
  • 59
  • 1
  • 1
  • 3
  • replace your MAIL_HOST=mailhog with MAIL_HOST=0.0.0.0 – Chinh Nguyen May 21 '21 at 08:12
  • You will need to add an entry to your hosts file like this `127.0.0.1 mailhog` otherwise like others have mentioned, replace mailhog with your local IP. I think Laravel is assuming that you are using containers out of the box. – Adam Patterson Mar 28 '22 at 14:51

3 Answers3

6

Do you use sail package for laravel? If you are using laravel sail you should set:

MAIL_HOST=mailhog

Otherwise it must be:

MAIL_HOST=localhost

Also enter a value for MAIL_FROM_ADDRESS:

MAIL_FROM_ADDRESS=a@gmail.com
ParisaN
  • 1,816
  • 2
  • 23
  • 55
0

In recent versions of Laravel Homestead, if you take a look at the Homestead.yml file, almost at the top you can get the IP address set for the Homestead Virtual Machine.

Copy that address to your .env file and set it instead of mailhog:

MAIL_HOST=192.168.56.56 #mailhog

Then you can access Mailhog with your browser by typing

http://192.168.56.56:8025/

Pathros
  • 10,042
  • 20
  • 90
  • 156
0

This problem occurs when some changes have been made to files, specifically in .env file. I was facing the same issue and solved by this solution.

Clear cache using artisan command

 php artisan cache:clear

Clear config

php artisan config:clear

Restart your server

 sudo service apache2 restart

More: Try clearing browsers cache & cookies.

Qazi Ammar
  • 953
  • 1
  • 8
  • 23