Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling PHP sendmail for development environment

I'm in a LAMP environment working on a system that sends out a lot of email notifications. I'd like a way to keep PHP from sending out actual emails in my development environment. Right now, I'm commenting out all of the mail() lines, but this is starting to cause confusion downstream with the QA people because they are removing the commented out lines and pushing them to the testers.

Any simple way disable sendmail in PHP without throwing an error?

like image 539
random21 Avatar asked Jan 18 '23 06:01

random21


2 Answers

You could also set up a small php script like described here to write the mails 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 your php.ini

like image 197
chiborg Avatar answered Jan 20 '23 16:01

chiborg


another solution for your problem is to setup your local postfix to local delivery. every email will be send to your local email account!

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

like image 31
silly Avatar answered Jan 20 '23 17:01

silly