NowPublic got serious about testing and hired Rok Zlender. Our first project together is email testing. He have mentioned fakemail by the same merry band that has written simpletest. This is a SMTP server which does not deliver anything just writes everything into a file. I began Googling in earnest and after about a quarter hour I realized this does not a full fledged SMTP server -- php.ini has a sendmail_path. This lead to the forthcoming, truly complicated little script:
#!/usr/bin/php <?php $input = file_get_contents('php://stdin'); preg_match('|^To: (.*)|', $input, $matches); $t = tempnam("/tmp/m", $matches[1]); file_put_contents($t, $input);
Name this for example sendmail.php , add it to php.ini as sendmail_path=/path/to/sendmail.php
and create a writeable directory in /tmp called m. Everything sent by php mail()
will land in there.
Commenting on this Story is closed.
do not forget to make the script executable and changing php.ini mandates restarting Apache usually. Also, for automated testing it might be better to use the file name directly nad not
tempnam()
it.also, for poor souls still running PHP4, file_put_contents() happens to be PHP5 only, so you'll want to replace that with:
// Write the contents of the mail to the file.
$handle = fopen($t, 'w');
fwrite($handle, $input);
fclose($handle);