Solved

PHP send email experiences a significant delay when sending

Posted on 2013-05-22
3
936 Views
Last Modified: 2013-06-05
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
Comment
Question by:DanielAttard
  • 2
3 Comments
 
LVL 16

Expert Comment

by:Chris Harte
ID: 39189048
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
 

Accepted Solution

by:
DanielAttard earned 0 total points
ID: 39189057
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
 

Author Closing Comment

by:DanielAttard
ID: 39221488
I figured out the solution after posting the question.  This comment is what solved the problem for me.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to count occurrences of each item in an array.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now