0

On a new server I am noticing that mail is being delivered much later than it should. It does not happen all the time, but enough to where it is bothering me and want to figure out the problem.

Please do not tell me to use a mailer class or something else. I have used php's mail() for simple stuff like this years and never had a problem until now so it must be a setting or something weird on this server.

I receive the emails they are just delayed and it happens randomly it appears.

Example trace for an email (notice the sent and out time) :

Event: success success 
User: user 
Domain: sending.com 
Sender: user@server.example.com 
Sent Time: Feb 2, 2015 3:47:15 PM 
Sender Host: localhost 
Sender IP: 127.0.0.1 
Authentication: localuser 
Spam Score:  
Recipient: support@receiver.com 
Delivery User: -remote- 
Delivery Domain:  
Delivered To: support@receiver.com 
Router: lookuphost 
Transport: remote_smtp 
Out Time: Feb 3, 2015 2:04:02 AM 
ID: 1YINtp-00067R-8i 
Delivery Host: receiver.com 
Delivery IP: 111.111.111.111 
Size: 836 bytes 
Result: Message accepted 

Here is the simple function I wrote and use to send mail :

// Send Mail
function send_mail($to,$from,$subject,$message) 
{ 
    // Create the email 
    $headers = '';
    $headers .= "From: ".$from."\r\n";
    $headers .= "Reply-to: ".$from."\r\n";
    $headers .= "Return-Path: ".$from."\r\n";
    $headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Date: " . date('r', time()) . "\r\n";

    mail($to,$subject,$message,$headers);
}
user756659
  • 2,814
  • 9
  • 41
  • 94

1 Answers1

0

That sounds a bit like a Greylisting. Some providers make a Greylisting and delay the emails. Another thing is remove the Message ID and let the mailserver manage that id. It make not so much sense to set that manually.

René Höhle
  • 24,401
  • 22
  • 66
  • 73
  • I'll try that - now that you said that all my other sites where I use mail() I don't supply the id. I don't remember when or why I put that in the function - must've been modifying something else that was there. Will also look into the greylisting. Thanks for the comment and time! – user756659 Feb 08 '15 at 00:33
  • Welp... removing the message id did not solve anything... I still have no idea what the problem could be. – user756659 Feb 18 '15 at 04:54
  • Then you should check your mailserver configuration. In most times a greylisting from a contact form is normal. – René Höhle Feb 18 '15 at 08:25
  • Where would I begin with that? This is hosted on a dedicated server, however, not mine. I find it strange that the server would be greylisting its own mail essentially. I use the exact same code on my own sites through my server and have never experienced this issue over the span of many years. Is the fact it is sending it elsewhere (to an email address not hosted on its server) part of the problem? It is sent from the site hosted on his, but delivered to the email/site hosted on mine. – user756659 Feb 18 '15 at 20:22