Disabling PHP sendmail for the development environment

I work in a LAMP environment that sends a lot of email notifications. I would like PHP to not send the actual emails in my development environment. Right now, I am commenting on all the mail () lines, but this is starting to cause a mess downstream with the QA people, because they delete the commented lines and push them to the testers.

Any easy way to disable sendmail in PHP without error?

+4
source share
5 answers

You can also configure a small php script, as described here , to write letters to var/log/mails :

 #!/usr/bin/php <?php $input = file_get_contents('php://stdin'); preg_match('|^To: (.*)|', $input, $matches); $filename = tempnam('/var/log/mails', $matches[1] . '.'); file_put_contents($filename, $input); 

Put the script in /usr/local/bin/sendmail , make it executable and put the line

 sendmail_path = /usr/local/bin/sendmail 

in php.ini

+3
source

another solution for your problem is to configure the local postfix to local delivery. Each email will be sent to your email address!

https://serverfault.com/questions/137591/postifx-disable-local-delivery

+2
source

Take a look at Fakemail or smtp4dev (the latter is for windows only). These tools allow you to not change the code and send email messages.

+2
source

Why don't you just use Mailerclass, for example:

  class MyMailer { private static $is_development_state = true; public static function mail(...) { if (self::$is_development_state) { ... } } } 

I mean: mail refactoring in MyMailer :: mail can do every IDE for you;)

+1
source

You can also try using the override_function method in PHP:

http://php.net/manual/en/function.override-function.php

This allows us to decompose the mail () function into a dummy function. This way, nothing happens, but the code will still work in production if you comment on the override_function function for your production environment.

+1
source

Source: https://habr.com/ru/post/1400618/


All Articles