Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using sSMTP with PHP for e-mail sending and it works fine.

The problem is that sSMTP performs the delivery synchronously which adds latency to my PHP scripts, letting the user waiting a little too long.

Is there a way to make it work non-blocking?

(I though of a hack on the shell, to start the sSMTP process on the background or something, and return earlier back to PHP, but I could not make it work.)

share|improve this question

Yes use one of the nullmailers which supports queueing or a full MTA instead of ssmtp. While you could write a wrapper around SSMTP, it'll need to fork and setsid to isolate from the calling php process.

share|improve this answer

This works with sendmail piping. Here is an example of what the data that gets piped looks like

Subject: Your Subject Here
X-PHP-Originating-Script: 0:MailSender.class.php
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1
From: First Last <>


Save this script as /usr/sbin/sendmail

# sendmail wrapper for ssmtp to send email asynchronously

echo "$stdin" > $TMP
body=`cat $TMP`

# Create the email and store in file
echo "ssmtp -t <<EOF " > $TMP
echo "$body" >> $TMP
echo "EOF" >> $TMP
echo "rm -f $TMP" >> $TMP

# Send the email
sh $TMP &
share|improve this answer

You can use gearman or other similar techniques do make blocking things asynchronously. See

share|improve this answer
up vote 0 down vote accepted

Ok, I figured it out! Using the script command we can write a wrapper:

script -q -c "/usr/sbin/ssmtp $*" /dev/null
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.