Solved

PHP send email experiences a significant delay when sending

Posted on 2013-05-22
3
969 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL limit and not so limited 13 36
Display field if column exists 7 33
Put POST values into cookies. 14 34
Prevent certain words from being typed in a form 6 28
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

749 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