A strange problem with PHP mail () on Linux

This is the case when it "works on my machine." In addition, my machine is Windows, and the target is some kind of Linux.

The idea is that the function mail()puts a new line between the headers MIME-Versionand Content-Typethereby violates all this. Here is the code as simple as possible:

<?php
        $HTMLPart = chunk_split(base64_encode('<html><body style="color: red">Test.</body></html>'));
        $PlaintextPart = chunk_split(base64_encode('>>> TEST <<<'));

$Headers     =<<<AKAM
From: "My Test" <my@mail.com>
Reply-To: my@mail.com
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="9-1410065408-1410065408=:27514"
AKAM;

$Body        =<<<AKAM
This is a multi-part message in MIME format.

--9-1410065408-1410065408=:27514
Content-Type: text/plain; charset="windows-1252"
Content-Transfer-Encoding: base64

$PlaintextPart
--9-1410065408-1410065408=:27514
Content-Type: text/html; charset="windows-1252"
Content-Transfer-Encoding: base64

$HTMLPart
--9-1410065408-1410065408=:27514--
AKAM;
    echo 'Try 3: ';
    echo mail('your@mail.com', 'Testmail', $Body, $Headers) ? 'WIN' : 'FAIL';
?>
+3
source share
1 answer

You probably have a carriage return wherever there is a line. Windows uses CR + LF to complete the lines, but Linux uses only the line channel.

+3
source

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


All Articles