Sendmail on Development Machines

Lately, I've been working a lot with mail scripts, which may use PHP's mail() function, or in some cases may even talk directly to sendmail. In order to make sure I don't accidentally email any customers, I use Rob Allen's script to reformat emails so they always go to my mailbox, and nowhere else.

Because Rob's script will only affect calls to PHP's mail() function, I needed to cheat slightly to catch the edge cases where sendmail is called directly. I achieved this my moving the real sendmail out of the way (naming it sendmail_real), and placing Rob's script in its place, edited to use the new path to "real" sendmail.

To make it even easier to use, I bashed together a small PHP script to automatically install the sendmail hack. Simply run the following in Terminal (it's meant to all be a single line):

sudo php -r "$(curl -fksSL https://gist.github.com/raw/59d9f9bae604cb4d012c/e8989e54f7d08a376086334005bd517b3a700375/sendmailRedirect.php)"

Naturally, you may be a little wary of running random scripts on your machine from an untrusted source, so if you want to check what it's going to run, check out the source yourself.

Sendmail on Development Machines
Mat Gadd