Skip to content

Instantly share code, notes, and snippets.

@joram77
Last active July 17, 2021 07:46
Show Gist options
  • Save joram77/dadc07123bd605e099e462919a12df6b to your computer and use it in GitHub Desktop.
Save joram77/dadc07123bd605e099e462919a12df6b to your computer and use it in GitHub Desktop.
Set up mailhog and configure PHP sendmail to use mhsendmail on macos

Mailhog and mhsendmail as PHP sendmail on macos

Useful for intercepting all PHP mails in a web interface when developing on your localhost. This uses the mhsendmail command for the PHP configuration instead of the normal sendmail command to avoid sending mails to the WWW when testing.

  1. install go

  2. install mhsendmail

    go get github.com/mailhog/mhsendmail
    
  3. install mailhog

    sudo port selfupdate && sudo port install mailhog
    
  4. test mailhog running

    sudo lsof -nP -i4TCP:8025 | grep LISTEN\n
    sudo lsof -nP -i4TCP:1025 | grep LISTEN\n
    
  5. php.ini changes

    [mail function]
    SMTP =
    sendmail_from = [email protected]
    sendmail_path = "/Users/joram/go/bin/mhsendmail"
    
  6. restart apache

  7. test php mail

    php -r "\$from = \$to = '[email protected]'; \$x = mail(\$to, 'subject'.time(), 'Hello World', 'From: '. \$from); var_dump(\$x);"
    
  8. test mailhog inbox

    http://localhost:8025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment