将所有邮件重定向到文件

Years ago, I ran across a short snippet of inline bash code that went into the php.ini file at the sendmail_path config entry. The purpose of the inline bash snippet was to redirect all mail to a file. Unfortunately, I lost the snippet. I want to use this for my development machine. Has anyone ever seen a snippet like this?

$ php -d sendmail_path="cat - >> /tmp/mailfile" -r "var_dump(mail('me@localhost','foo','bar'));"
bool(true)
$ cat /tmp/mailfile 
To: me@localhost
Subject: foo
X-PHP-Originating-Script: 1000:Command line code


bar

"cat" based one liner may create race condition when two email are send in parallel. IMHO they may be fit for low load simple est environment.

I would recommend solution based e.g. on procmail. Procmail can use locks when delivering to mailbox file or deliver to maildir.

sendmail_path="/usr/bin/procmail -m /etc/procmailrcs/catch-mail.rc"

/etc/procmailrcs/catch-mail.rc :

# deliver messages to /tmp/mailfile mailbox file
DEFAULT=/tmp/mailfile