Skip to content

Instantly share code, notes, and snippets.

@nathanieltubb
Last active December 7, 2017 03:11
Show Gist options
  • Save nathanieltubb/64bde22366e3cdf1ac6379154a3a58db to your computer and use it in GitHub Desktop.
Save nathanieltubb/64bde22366e3cdf1ac6379154a3a58db to your computer and use it in GitHub Desktop.
Enabling Mailcatcher for local PHP debugging.

Mailcatcher

https://mailcatcher.me/

This is a Ruby gem which collects outgoing email messages from your app and displays them in a webmail portal.

The general install directions are provided on the site, however there are several variances with my own developement environment which have proved a challenge.

Using RVM?

If you are using RVM it might be recommended to install this gem globally for all environments.

rvm @global do gem install mailcatcher

The PHP Part

Using A Custom Installed (Homebrew) Version of PHP?

If you are running on a Mac and have installed an updated version of PHP using Homebrew, your php.ini file is most likely not in the same location as with the default Mac installation. To find where your current configuration file is located run the following command.

php --ini

For example my configuration path is /usr/local/etc/php/7.0/php.ini not the default Mac's PHP path /etc/php.ini.

Edit The PHP.ini

Edit your php.ini like the following. The main gotcha with this is swapping the port number. The default is 25, but mailcatcher listens on 1025 by default. Note that depending how you installed mailcatcher, whether or not you are using RVM, may change the exact path to the mailcatcher executable.

smtp_port = 1025

sendmail_path = /usr/bin/env catchmail --smtp-port 1025 -f me@localhost

Restart Apache / NGINX

You will need to restart your local webserver, Apache or NGINX, in order for your changes to take affect.

To check your configuration is loaded make an info.php file in your web root and add the following PHP code to output the PHP info.

<?php
phpinfo();

Load this file up in your browser and search for the SMTP settings. These lines should match the settings you entered in the php.ini file.

Run Mailcatcher

Now you are ready to run mailcatcher with the following. This will start the webmail portal. The webmail URL will also be output by this command.

mailcatcher

There is the option to clear and quit mailcatcher from within the webmail interface.

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