Sending mail from php: headers are interpreted as body?

When I send mail with php with \ r \ n as a line break in the headers ( as it should be in accordance with the documentation )

$headers = "From: $email\r\n"; 
$headers .= "Reply-To:  Just me <$email>\r\n"; 
$headers .= 'Content-type: text/plain; charset=iso-8859-1' . "\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$subject = "Hello world";
$body = "<html><p>Hey, whats up?</p></html>";

mail($to, $subject, $body, $headers);

Some email clients will interpret \ r \ n as two line breaks. Therefore, for this mail () above the real mail content, the following will look:

X-Message-Delivery: Vj0LEdMMtPAYT0xO0Q9MTtTQ0w9MA==
X-Message-Status: n
Received: from server75.publicompserver.de ([92.43.108.63]) by snt0-mc2-f13.Snt0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675);
 Thu, 9 Dec 2010 12:09:22 -0800
Message-ID: <40177C.70807@justme.org>
[lots of other headers]
Date: Thu, 09 Dec 2010 21:09:32 +0100
X-OriginalArrivalTime: 09 Dec 2010 20:09:22.0873 (UTC) FILETIME=[F88C3A90:01CB97DC]
From: $email

Reply-To:  Just me <$email>

Content-type: text/html; charset=iso-8859-1

Content-Transfer-Encoding: 8bit

<html><p>Hey, whats up?</p></html>

Now some clients (e.g. googlemail) will ignore these extra lines. Others (thunderbird) interpret the first extra line as the end of the headers and interpret the rest of the header lines as part of the body (losing header information, in this case displaying mail as text instead of html).

I also saw this problem on other mail servers.

? \r\n - , - ? ? , \n \r\n , " \r\n", , ?

+3
3

http://php.net/manual/en/function.mail.php: " , LF (\n). Unix- LF CRLF ( CR, CRLF). , " RFC 2822".

, : , .

+8

. - (CRLF LF). PHP PHP_EOL, PHP .

0

In your code, you use \ r \ n for some header lines and only \ n for others. Perhaps this problem will not occur if you are consistent.

0
source

Source: https://habr.com/ru/post/1779718/


All Articles