The drop is always movingYou know that saying about standing on the shoulders of giants? Drupal is standing on a huge pile of midgetsAll content management systems suck, Drupal just happens to suck less.Popular open source software is more secure than unpopular open source software, because insecure software becomes unpopular fast. [That doesn't happen for proprietary software.]Drupal makes sandwiches happen.There is a module for that

Testing email

Submitted by nk on Tue, 2007-07-24 12:18

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:

$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.

Submitted by nk on Tue, 2007-07-24 12:43.

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.

Submitted by on Sat, 2007-08-18 14:51.

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);