Disable PHP mailing on Mac OS?

1

2

I'm developing a web application in PHP, and my Macbook, running Snow Leopard, is actually sending emails when PHP's mail() function is called. It's emailing customers, and that's BAD.

I COULD prevent this in my code, but I'd rather just disable mailing for my machine. Is there a way to do this under Mac OS?

Chad Johnson

Posted 2009-12-15T21:25:52.867

Reputation: 382

2If you're doing development on your macbook, you should really not have customer information in the db. Only test data should be in there. Imagine how much could be compromised if you lost your laptop, or worse, it was stolen. – davethegr8 – 2009-12-15T22:47:26.713

Answers

3

The simplest answer is to have a switch in your send logic that checks whether or not DEVELOPMENT is defined. If it is, it outputs the mail to a file, other wise, it assumes a production environment and continues with the normal send process.

All you need to do is set DEVELOPMENT = TRUE in your config and you can play around without disturbing customers!

Your local postfix config is located in /etc/postfix. There seems to be a duplicate at /private/etc/postfix but i'm not so familiar with OSX. On linux i could just remove the daemon and stop the service from running. This might cause runtime errors for your programs and seems unecessary.

deau

Posted 2009-12-15T21:25:52.867

Reputation: 164

1This is exactly what I ended up doing: 1) used an IS_DEVELOPER flag and 2) disabled postfix. Actually for (2), I moved /usr/sbin/sendmail to /usr/sbin/sendmail.original and put a dummy sh script in place of sendmail, as I read that sendmail uses Postfix when Postfix is running but can still send out emails otherwise. I don't need outgoing email functionality on this machine, so this solution works for me. – Chad Johnson – 2009-12-16T01:13:43.313

2/etc/ is a symlink to /private/etc/ so they're the same file. (The same occurs with /var and /tmp as well on OS X). – Chealion – 2009-12-16T04:34:06.510

2

To partially disable postfix run sudo launchctl unload /System/Library/LaunchDaemons/org.postfix.master.plist

However the mail you're attempting to send will get stuck in /var/spool/postfix/maildrop but will not send.

Chealion

Posted 2009-12-15T21:25:52.867

Reputation: 22 932

1

Easiest thing I can think of (If you only use web mail or Imap), simply at the network (router) level block outgoing of port 25 from your machine, or use the OS X firewall and block port 25 outgoing.

IF this doesn't work, I would simply look at putting a non existent relay in to your php.ini so all mail simply fails to send....

However, you would be better off using a real relay that simply does not send out but looks like it does - blocking at the firewall or application or fake relay could all produce errors that you may not account for and cause problems when you do actually go live.

William Hilsum

Posted 2009-12-15T21:25:52.867

Reputation: 111 572

1

You need to compartmentalize your development environment from your release environment.

That is the solution to your real problem.

Paul Nathan

Posted 2009-12-15T21:25:52.867

Reputation: 1 616