By default, php mail() is using sendmail, using a 3 steps process:

  • mail() forks sendmail process
  • sendmail attempts to send message to destination server
  • sendmail returns to mail() when the message is sent

On a large batch of emails, you'll want to reduce the time spent of each mail() call.

Enter background delivery mode.


Update your your php.ini with:

sendmail_path = /usr/sbin/sendmail -t -i -O DeliveryMode=b

This sets the delivery mode to background: the MTA will put the message in the queue and sendmail will return almost instantly in mail().


Note: If you're using Postfix as you MTA, it seems that this option is not necessary, since Postfix is not monolithic and always queues the message [see Postfix mailing lists].