How do I install Mailhog?


Platform.Sh offers e-mail sending from your container but due to technically limitations, is unable to provide any logging capability for it. Mailhog is a golang application that allows you to catch and log emails being sent through sendmail.
This allows you to have a better overview on which mails are being sent via sendmail.

For more control over your email sending, please do use your own email server or create your own postmarkapp or sendgrid mail account.


MailHog is a wonderfully written efficient piece of software, but it does take away a bit of resources away from your main app. If you are only interested in debugging emails on your dev environment you can make the start_mailhog script conditional (see further in the article).


  • E-mail of your app is currently being sent through sendmail.


Install components

  • First thing to do is create a new file. This will download MailHog from github and put it in your build.
run() {
    if [ ! -f "$PLATFORM_CACHE_DIR/MailHog" ];
        echo "Cache empty, downloading from github"
        echo "Already see it in cache, reusing"

    # Create a php.ini file that overwrites the default sendmail_path
    echo 'sendmail_path=/app/mhsendmail' > $PLATFORM_APP_DIR/php.ini

install_mailhog() {
    curl -SsL -o MailHog
    chmod +x MailHog

install_mhsendmail() {
    curl -SsL -o mhsendmail
    chmod +x mhsendmail

copy_lib_to_cache() {
    echo "Copy to cache..."

copy_lib_from_cache() {
    echo "Copy from cache... "

  • Then, tell your build hook to run it. It will automatically put the binaries in the build cache so subsequent builds should be quick. If you want to upgrade the version of MailHog later, simply clear the build cache platform project:clear-build-cache.

In add:

    build: |
        set -e

Starting MailHog and PHP

  • Now we have to tell the system to start both MailHog AND your php application. Create a new file called
echo "Killing old processes"
pkill MailHog || true
pkill php-fpm || true
pkill php-fpm8.1-zts || true

if [ "$PLATFORM_ENVIRONMENT_TYPE" = production ]; then
    echo "Only starting php, since we're running on production environment"
    echo "Starting MailHog and php-fpm"
    ./MailHog & /usr/bin/start-php-app

Note: the above script is only starting MailHog for development environments. You can change the script if you want to run it on production as well. But do be aware that this can cause additional load on the container. (although honestly, this should be fairly limited unless you send huge quantities of e-mail).

  • Then, add the start command to your
        start: 'bash'


  • Commit and push the code and verify that the build correctly downloaded the MailHog binary. And verify that your site is still running.

git add && git commit -m "Adding mailhog" && platform push

Accessing the MailHog web UI

  • MailHog will be running on port 8025, but this is not accesible from the outside world. This is good, because we don’t want visitors to your site to actually visit this. However, you can access it by setting up an ssh tunnel to your local machine.

The following command tells ssh to open a pipe from port 8025 on the container, to 8025 on your local machine:

ssh $(platform ssh --pipe) -n -N -L 8025:localhost:8025

Then, open firefox and go to http://localhost:8025 to see the MailHog webui in all its glory.

  • When you start sending emails, you should see them pop up in the UI.