Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP send email experiences a significant delay when sending

Posted on 2013-05-22
3
Medium Priority
?
1,055 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
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…
Suggested Courses

618 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