[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1075
  • Last Modified:

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:

<?php
$to = "me@mysite.ca";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "me@myothersite.ca";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
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.
0
DanielAttard
Asked:
DanielAttard
  • 2
1 Solution
 
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.
0
 
DanielAttardAuthor 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:

127.0.0.1      localhost
127.0.1.1      webserver

to this:

127.0.0.1      localhost localhost.localdomain webserver

everything works fine without delay.
0
 
DanielAttardAuthor Commented:
I figured out the solution after posting the question.  This comment is what solved the problem for me.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now