How to setup Mailhog in Ubuntu PHP Magento 2?

MailHog tools are used to test mail functionality from your local development environment.

If you are using Linux/Ubuntu OS with PHP language and want to set up MailHog for your local setup. MailHog tool is the best suited for your system to test web application mails.

First You need to install MailHog using the Command Line Interface (CLI),

Install MailHog,  go get

Mhsendmail is a Send mail utility created to send emails via MailHog.

Install mhsendmail,  go get

copy MailHog and mhsendmail to the /usr/local/bin path,

Just replace system_user with your system username.

You can get the current username of the system in Linux by command,

Now Modify the php.ini to setup MailHog path,
I am working with PHP 7.4 version, php.ini path location would be /etc/php/7.4/apache2/

From Command Line, Run the command to modify the file,
sudo gedit /etc/php/7.4/apache2/php.ini

Now update ;sendmail_path = with the given line. Remove the semicolon from the starting and update the path,
sendmail_path = /usr/local/bin/mhsendmail
Save the file and restart the PHP to get it to work.

Final Step:

Go To CLI, run the command,

You will see URLs like
Open this URL in the browser and you will be able to see the web interface of  Mailhog.

You can see more details about MailHog by MailHog link.