Developing software in the Real World

Sending test emails from PHP

I’ve written before about redirecting email while developing using a trap mail script on my development system. Other people also like MailCatcher.

I’ve recently switched to using a simple PHP script that creates a elm file on disk that can be opened by Apple’s Mail client. This solution is much faster as there is no SMTP processing involved.

Adam Royle came up with this solution in his article Setup a testing mail server using PHP on Mac OS X, so thank you Adam!

In summary:

  • Create ~/smtp_out
  • Create ~/smtp_out/smtp_catcher.php with these contents:
  • Make ~/smtp_out/smtp_catcher.php executable
  • Update php.ini and set:

    (Change rob to your username!)
  • Restart Apache
  • Give Apache permission to open Mail, by updating sudoers:
    • sudo visudo
    • Add this to the end:

      (Again, change rob to your username!)

Read Adam’s post for the full details on what’s going on.

It’s a nice solution and I’m liking it!