Tom Willmot
Tom Willmot

Reputation: 85

Is it possible to only allow PHP mail to send to certain email address's at a php.ini level

Whenever I'm doing development on a site which sends emails to users I have to remember to comment out the mail() code so that I don't accidentally trigger the notification email whilst fiddling around and debugging, it's a pain and occasionally I forget and send emails to people when I didn't mean to.

is there a way to enforce a whitelist at the php.ini level (or some other low level) of email addresses that mail() is allowed to send too?

Do other people have clever ways of avoiding this issue?

Upvotes: 3

Views: 404

Answers (3)

Piskvor left the building
Piskvor left the building

Reputation: 92752

Not at that level, but there are various workarounds:

  • set your outgoing SMTP server to one that doesn't forward the mail (i.e. forbid the forwarding at SMTP server; this may be easiest, as you don't have to handle the filtering anywhere in your code)
  • use a wrapper like phpMailer, and extend its send() method, do the filtering there (useful as you can change the actual recipient to be e.g. [email protected], so you'll still see that mails are going out, but redirected to yourself)

Upvotes: 0

jrn.ak
jrn.ak

Reputation: 36619

Why not have a maintenance mode setting for your site?

if ($maintenance_mode) {
    // only send mail to admin
} else {
    // send mail to users
}

Upvotes: 0

Brad
Brad

Reputation: 163272

I would do this at the SMTP level. Configure it there and have PHP use a specific SMTP server that is only for development.

Upvotes: 3

Related Questions