?
Solved

PHP send email experiences a significant delay when sending

Posted on 2013-05-22
3
Medium Priority
?
1,025 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

765 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