开发者

Disable PHP mailing on Mac OS?

开发者 https://www.devze.com 2022-12-14 15:15 出处:网络
I\'m developing a web application in PHP, a开发者_JAVA技巧nd my Macbook, running Snow Leopard, is actually sending emails when PHP\'s mail() function is called. It\'s emailing customers, and that\'s B

I'm developing a web application in PHP, a开发者_JAVA技巧nd 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?


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.


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').


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.


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.


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


You could try the disable_functions option in php.ini.

eg: disable_functions = mail

0

精彩评论

暂无评论...
验证码 换一张
取 消