PHP send email experiences a significant delay when sending

I am configuring a new web server and using sendmail for sending email messages.  I am trying to figure out why this code simple, basic code takes over a minute to run:

$to = "";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "";
$headers = "From:" . $from;
echo "Mail Sent.";

Open in new window

When I look in firebug, I can see that it takes a long time for the code to run.

Any ideas?  Thank you.
Who is Participating?
DanielAttardConnect With a Mentor Author Commented:
Thanks for the comment.  My problem was that Sendmail looks for a fully qualified domain (FQDN) name, which I did not have in my hosts file.  Once I changed it from this:      localhost      webserver

to this:      localhost localhost.localdomain webserver

everything works fine without delay.
Chris HarteThaumaturgeCommented:
It is not the code. Mail() has to open and close an SMTP socket to work. It is probably establishing a connection to your mail server that is causing the delay.
DanielAttardAuthor Commented:
I figured out the solution after posting the question.  This comment is what solved the problem for me.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.