If you have local setup via Homestead or Valet, you might need to use smtp
setup for emails in your application. For local development, one of the choices is to use MailHog.
Setting up MailHog can be in many ways but in this article, we will talk about setting up docker container for it.
Following are the steps:
- Install docker desktop
You can go to this link and choose the desired application for your operating system.
- Create a folder called
docker-workspace
mkdir docker-workspace
- Go to the folder and create a new file
docker-compose.yml
cd docker-workspace
touch docker-compose.yml
- Open
docker-compose.yml
file and enter the following content:
version: "3.7"
services:
# SMTP Server
smtp:
platform: linux/x86_64
image: mailhog/mailhog
container_name: docker-workspace-smtp
logging:
driver: 'none'
ports:
- "8003:1025"
- "8100:8025"
networks:
- docker_workspace_network
networks:
docker_workspace_network:
driver: bridge
- Start the docker container via the following command:
docker-compose up -d
- Go to http://localhost:8100/ and confirm the MailHog setup and you should see the following on successful setup
- In your Laravel application change the
.env
to the following:
MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=8003
MAIL_USERNAME=''
MAIL_PASSWORD=''
MAIL_ENCRYPTION=null
- Now, sending emails from you app will start showing up in the MailHog
Happy Coding!
Top comments (0)