Mailcatcher setup for PHP on Mac OSX

In this post I’m going to talk about installing Mailcatcher for PHP on Mac OSX.  It is particularly useful when developing new websites as you can test emails without worrying if they are going out to a recipient.

This has two advantages:

  1. You can rapidly test emails without worrying that it will go out to it’s recipient
  2. You can save money on services such as postmark or mailchimp since development emails no longer will hit that service.

Installing Mailcatcher

Mac’s come preinstalled with Ruby so it’s as simple as installing a ruby gem. This is just a package manager which allows you to easily install programs and libraries. To install mailcatcher simply run the following.

Let it do it’s thing which will involve installed any dependencies for mailcatcher and finish setting up.

One completed successfully you can run the following:

If the program started successfully you will get the following:

If you open http://127.0.0.1:1080 you will be presented with the mailcatcher interface.

Screenshot of Mailcatcher interface

That’s the first part and mailcatcher is now setup for the mac. Next we need to link it with php, which is covered in the next section.

Setting Mailcatcher up with PHP

Once this has been setup we now need to link it to PHP.

First we need to find out where catchmail (a program installed with mailcatcher) has installed to. I’m going to assume it’ll be located in the following directory:

However if you are unsure you can run the following command:

This will return the directory path for catchmail. We will need this later.

Next we need to find the php.ini file so that we can configure catchmail to respond to the mail() command in php. You can find this by running

And finding the configuration file path function. e.g.

Once found open up the file using your favourite command line text editor:

Update the following:

to

And update:

to

Once the above has been done save the file and quit out.

Restart php locally and try to send a test email using the mail() command.

If you open up the following url: http://127.0.0.1:1080

You should now see your email going into Mailcatcher.

Congratulations you now have a working setup for testing development emails. Good job!

Join the conversation

2 Comments

  1. Hello
    Thank you for the document it’s simple and working well.
    I only have one problem. Mailcatcher puts subject in the “From” field and From in the “Subject” field.
    How is it possible ?
    How can i correct it ?
    Thank you for your answer.
    Best regards

    1. Hi Bernard,

      Thanks for your comment. May I ask how you are sending the email out? There could be a configuration issue with the module or the function you are using.

      Thanks,
      Jamie

Leave a comment

Your email address will not be published. Required fields are marked *