tags:

views:

64

answers:

6

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?

+1  A: 

That means you must have installed sendmail (or something that pretends to be sendmail) at some point, but you should probably prevent this in your code in addition to disabling it.

Azeem.Butt
OS X comes with a built-in version of postfix.
Ned Deily
Surely moving /usr/sbin/sendmail to /usr/sbin/sendmail.original and replacing sendmail with an empty sh script should do the trick globally.
Chad Johnson
It shouldn't come configured to actually do anything.
Azeem.Butt
Clearly it is doing something...and I did not configure it to do so.
Chad Johnson
I remain unconvinced that you would know whether or not you had.
Azeem.Butt
ps aux|grep -i sendmail and ps aux|grep -i postfix showed that both of these programs were running. Yes, I should have mentioned this.
Chad Johnson
A: 

You should be able to shut mail() up by changing the SENDMAIL_PATH setting. Documentation here

Pekka
+1  A: 

Why not move the e-mail address to a config file, and then on your machine use a different set of addresses? Things like that shouldn't be hard-coded into the application.

For example, in my apps I have a Config database that houses all that info. When the app is being worked on, the Config table is set with dummy or harmless addresses/info. That way you don't have to mess with anything on the development PC(s) as well as make it easier to maintain, like if the e-mail addresses change.

dragonmantank
Why the downvote? This is actually a good idea and cleaner than castrating mail().
Pekka
My app has hundreds of thousands of user email addresses. Bad solution. Though, I suppose a down-vote was unfair, as not enough context was provided.
Chad Johnson
It's not an accident that most web application frameworks maintain a notion of a production environment and a non-production environment and make runtime decisions accordingly. The "bad solution" would seem to be entirely yours.
Azeem.Butt
It's very childish of you to downrate me in spite, as my question pertains to disabling mailing. Rating of the question should not be based on whether the end-goal (being unrelated) is a good solution.
Chad Johnson
Give me a button to rate you as a developer independent of your questions and I'll be the first one to use it.
Azeem.Butt
Besides dude, he specifically mentioned relocating all emails which is NOT a good solution. A solution would be to use a flag to indicate whether the machine is a development one (eg. Config::get('IS_DEVELOPER')). THAT I can agree with--not his, which is what I down-rated.
Chad Johnson
A: 

You could try the disable_functions option in php.ini.

eg: disable_functions = mail

Blair McMillan
Won't this lead to an error where his script tries to send mail?
Pekka
True, but it is a way to disable the mail function, which was what the question asked.
Blair McMillan
+3  A: 

I typically use a wrapper class for mail() that checks for a constant (something like DEBUG_MODE) and sends the email to me instead of the original recipient (and includes all of the original recipients in the mail body so I can confirm things are working). It's a bit of extra work the first time, but it means I don't have to worry about sending email to "real" people but I still know things are working.

I've posted a simple example. It could use a lot of improvements (header handling, making sure cc and bcc fields also get stripped), but it'll get you most of the way home.

Tom
+1 Decoupling functionality like this is a Good Idea (tm)
Bryan Ross
+1  A: 

Thank you for the posts. Here is my solution.

I have moved /usr/sbin/sendmail to /usr/sbin/sendmail.original and replaced /usr/sbin/sendmail with a dummy sh script. I do not want this particular machine ever sending email.

I have also implemented a second solution, whereby I check whether the current machine is a development machine, and if so, no emails are sent out. For this I use a flag, Config::get('IS_DEVELOPER').

Chad Johnson