开发者

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

开发者 https://www.devze.com 2023-02-25 15:49 出处:网络
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 aro

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?


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


Why not have a maintenance mode setting for your site?

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


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. your.own.address@example.com, so you'll still see that mails are going out, but redirected to yourself)
0

精彩评论

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

关注公众号