Skip to content

Instantly share code, notes, and snippets.

@racheats
Created January 23, 2019 14:09
Show Gist options
  • Save racheats/0632a1d1572b82230e46e5f348ee926e to your computer and use it in GitHub Desktop.
Save racheats/0632a1d1572b82230e46e5f348ee926e to your computer and use it in GitHub Desktop.
Setup for mailhog installation on ubuntu xenial 16.04
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "Please run as root"
exit
fi
MAILHOG_URL=github.com/mailhog/MailHog
MHSENDMAIL_URL=github.com/mailhog/mhsendmail
MAILHOG_EXECUTABLE=/usr/local/bin/mailhog
MHSENDMAIL_EXECUTABLE=/usr/local/bin/mhsendmail
PHPINI_PATH="$( php --ini | grep /php.ini | awk -F: '{print $2}' )"
# verify golang installation
go version
# get mailhog and mailhandler installation
go get $MAILHOG_URL && go get $MHSENDMAIL_URL
# setup mailhog and mailhandler tobe accessible globally
cp $GOPATH/bin/MailHog $MAILHOG_EXECUTABLE && cp $GOPATH/bin/mhsendmail $MHSENDMAIL_EXECUTABLE
# set sendmail_path value on php.ini to mailhandler executable
sed -i "s/;sendmail_path.*/sendmail_path = /usr/local/bin/mhsendmail /" /etc/php/7.2/cli/php.ini
# create mailhog service to invoking on system booting
cat <<EOF >/etc/systemd/system/mailhog.service
[Unit]
Description=Mailhog service
[Service]
ExecStart=/usr/local/bin/mailhog -api-bind-addr 0.0.0.0:8025 -ui-bind-addr 0.0.0.0:8025 -smtp-bind-addr 127.0.0.1:1025
[Install]
WantedBy=multi-user.target
EOF
# start, enable and check mailhog status
systemctl start mailhog && systemctl enable mailhog && systemctl status mailhog
# test email submission
php -r "\$from = \$to = 'your.emailaddress@gmail.com'; \$x = mail(\$to, 'subject'.time(), 'Hello World', 'From: '. \$from); var_dump(\$x);"
@racheats
Copy link
Author

installation mailhog and mailhandler for PHP

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