laraveldockerlaravel-9mailhog

I'm trying to send mails through mailhog using laravel


type herehere is my .env :

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:p5lGXZTf7OB8BwTkbRBiBxoVn0yOO06tSyP/iChZJGA=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lara
DB_USERNAME=root
DB_PASSWORD=root

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

Im using docker so here is the part pf mailhog:

  mailhog:
    image: mailhog/mailhog
    ports:
      - 1025:1025
      - 8025:8025

and here is the error I'm getting when ever a new mail should be sent : Connection could not be established with host "mailhog:1025": stream_socket_client(): php_network_getaddresses: getaddrinfo for mailhog failed: Temporary failure in name resolution

I tried to send a mail notifications via mailhog but I'm getting an error when ever it should be sent


Solution

  • It is a frequent error that developers encounter when creating a new Laravel project. The default sender for the project is set as Mailhog, which is only supported when Laravel Sail is used as the development environment. Therefore, in case a different development environment is used, it is necessary to modify the configuration to avoid encountering problems.

    To solve this issue, it is recommended to set the mail host and port as follows in the .env file:

    MAIL_HOST=127.0.0.1
    MAIL_PORT=1025