PHP mail adds leading newline when no additional headers present

Viewed 802

I have encountered some odd behaviour using mail on PHP 5.4.17 on Mac OS X Mavericks. When I send a simple e-mail like this:

mail("me@example.com", "Test", "A line of text.");

the resulting e-mail contains a leading newline. I.e. the source looks like this:

(Other headers)
To: me@example.com
Subject: Test
X-PHP-Originating-Script: 501:-
Message-Id: ...
Date: Mon, 30 Dec 2013 14:52:49 +1300 (NZDT)
From: me@mymachine.local (Me)


A line of text.

However when I add an additional header (such as CC) to the command, the leading newline disappears:

mail("me@example.com", "Test", "A line of text.", "Cc: me@example.com\r\n");

results in:

(Other headers)
To: me@example.com
Subject: Test
X-PHP-Originating-Script: 501:-
Cc: me@example.com
Message-Id: ...
Date: Mon, 30 Dec 2013 14:53:33 +1300 (NZDT)
From: me@mymachine.local (Me)

A line of text.

How can I get the first line to not add this leading newline? I have tried passing NULL and "" as the $headers parameter to mail but this has no effect.

1 Answers
Related