title: Simulating sendmail with dummy script
body: <p>I created a small shell script which logs all of it's input to a log file, with which I had thought I could replace the sendmail binary and thus achieve a simple way to simulate e-mail delivery without actually setting up a working sendmail.</p>
  
  <p>This failed, however. For reasons I cannot understand.</p>
  
  <p>I've looked at the PHP mail.c source and as far as I can understand (mind you, I'm not very experienced in C), PHP executes and talks directly to the binary (set in <code>sendmail_path</code>). But no log files are being created when I replace the sendmail binary with my script and the script replacing sendmail will always create a log file when it's executed, regardless of if there's input present or not.</p>
  
  <p>The script itself works fine. Its' return codes should conform to that of sendmail's. With the difference that my script always returns 0, regardless of the input, since I'm not really interested in checking if the input is valid - just that I'm getting some.</p>
  
  <p>Is it possible to achieve what I want, i.e. using a sendmail simulator?</p>
  
  <p>The script source is provided below:</p>
  
  <pre><code>#!/bin/bash
  
  LOGDIR=/tmp/sendmail-sim
  NOW=$(date +%Y%m%dT%H%M)
  CNT=1
  FILENAME="$LOGDIR/$NOW.$CNT.log"
  
  while [ -f $FILENAME ]; do
      CNT=$(($CNT + 1))
      FILENAME="$LOGDIR/$NOW.$CNT.log"
  done
  
  echo "$0 $*" &gt; $FILENAME
  
  while read BUF
  do
      echo $BUF &gt;&gt; $FILENAME
  done
  
  exit 0
  </code></pre>
  
  <p>PS. My current sendmail (or actually, postfix) does receive email from PHP, but I don't want to actually send any email or need to go digging in its' mail queue in development.</p>