I use PHP to send an email like this:

 mail($email_recipient,$mail_subject,$mail_body,"From: $email_sender\r\nReply-to: $email_sender\r\n");

The $mail_body is perhaps 1kb. $email_recipient = $email_sender = "myaddress@gmail.com".

This takes 20 seconds to send on a mac os x server.

Here is some data from phpinfo:

sendmail_from   no value    no value
sendmail_path   /usr/sbin/sendmail -t -i    /usr/sbin/sendmail -t -i 
SMTP    localhost   localhost
smtp_port   25  25

Here is a snippet from my 'man sendmail' showing that it is really postfix underneath:

sendmail - Postfix to Sendmail compatibility interface

Server load avg in top is 0.25

What is the problem and how do I make this faster?

I would assume a reasonable time for simply queueing an email would be in the range of milliseconds instead of 20 seconds.

--

Some DNS timing tests which look ok to me:

;; Query time: 1 msec
real    0m0.005s
user    0m0.001s
sys     0m0.003s
admin$ dscacheutil -flushcache
admin$ time dig gmail.com MX
[...]
;; Query time: 1 msec
[...]
real    0m0.006s
user    0m0.001s
sys     0m0.003s
admin$

--

Some mail timing:

admin$ echo test | time mail -s subject2 myaddress@gmail.com
        0.00 real         0.00 user         0.00 sys

admin$ time php -r 'mail("myaddress@gmail.com","sub","body","From: myaddress@gmail.com\r\nRelply-to: myaddress@gmail.com\r\n");'

real    0m4.033s
user    0m0.015s
sys     0m1.523s

So for some reason, php mail takes significantly more time than normal mail from the shell.

link|improve this question
1  
this may be a dns problem, what does happens if you 'time dig gmail.com MX' . if that works then you don't have a dns problem.... oh try clearing your DNS cache and reissue the command , if you got a large delay you've got dns problems – The Unix Janitor Feb 9 at 16:01
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.