I run Ubuntu 10.04 and installed a LAMP stack with a "satellite" Postfix (used as a relay for my ISP's smtp).

In php.ini, I kept the sendmail pass to default so with -t -i arguments:

;sendmail_path =

I send emails like this:

$headers  = 'From: info@mydomain.com' . "\r\n";
$headers .= 'Reply-To: info@mydomain.com' . "\r\n";
$headers .= 'Return-Path: info@mydomain.com';

mail('recipient@mydomain.com', 'Email title', 'Text of the body.', $headers);

The emails recieved have this in the body (It should be in the header):

Reply-To: info@mydomain.com 
Message-Id: <20111027210218.6F32440DE7@mydomain.com>
Date: Thu, 27 Oct 2011 23:02:18 +0200 (CEST)

How can we fix that?

Note: The emails are working properly on other installs: Gentoo with qmail or Windows with smtp set to my isp's in the php.ini.

Here is the full header:

Return-Path: <www-data@mydomain.com>
Delivered-To: info@mydomain.com
Received: (qmail 28922 invoked from network); 27 Oct 2011 23:00:55 +0200
Received: from zhhdzmsp-mail12.myisp.com (
  by www.mydomain.com with SMTP; 27 Oct 2011 23:00:55 +0200
Return-Path: <www-data@mydomain.com>
X-FXIT-IP: IPv4[] Epoch[1319888334]
Received: from [] ([] helo=dev.mydomain.com)
    by zhhdzmsp-mail12.myisp.com (envelope-from <www-data@mydomain.com>)
    (ecelerity r()) with ESMTP
    id 6E/C0-28209-6D6C9AE4; Thu, 27 Oct 2011 21:02:14 +0000
Received: by dev.mydomain.com (Postfix, from userid 33)
    id 6F32440DE7; Thu, 27 Oct 2011 23:02:18 +0200 (CEST)
To: info@mydomain.com
Subject: Email Title
X-PHP-Originating-Script: 1000:helpdesk.php
From: toto@gmail.com
  • And what is in the header? – mailq Oct 27 '11 at 21:30
  • Voila. I modified the ips and the domains for privacy matters. Thanks. – Toto Oct 27 '11 at 21:36

Postfix translates "line feed" (\n) into "carriage-return line-feed" (\r\n). Try removing the \r and using just \n.

  • This is crazy. I cannot believe it was this... "If messages are not received, try using a LF (\n) only. Some poor quality Unix mail transfer agents replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822" php.net/manual/en/function.mail.php – Toto Oct 27 '11 at 22:02
  • Do you know if there is a way to handle correctly the "carriage-return line-feed" with Postfix (2.7.0)? – Toto Oct 27 '11 at 22:11
  • 1
    No, sorry. Postfix 2.9 has a new sendmail_fix_line_endings option which looks related postfix.org/sendmail.1.html – smin Oct 27 '11 at 22:33
  • Excellent link/info. Thanks. Postfix does not look like the ideal tool for my needs, so I finally installed Sendmail following the instructions on this page: geoffke.be/nieuws/13 – Toto Oct 27 '11 at 23:08

Your statements and the header don't match. Probably just a copy&paste error but is a bad starting point for diagnosis.

Then you have two Return-Path lines in the header and one in the body. THAT is strange and an indication for a bigger problem.

The overall problem is that you are trying to identify a problem with a header of a mail that went through four(!) email servers. And you then blame one of them as the culprit. But it can be any of them. Or most obvious none of the five as mail servers in general don't modify headers or bodies, except they are told to or required by RFC 5321. So if you want to analyze the problem you have to look how the mail arrives at the first server and not at the upcoming servers.

  • 1
    I find the first Return-Path: <www-data@mydomain.com> strange. It is the apache user. It overrides the specified one in the php code. – Toto Oct 27 '11 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.