当它“在我的机器上工作”时就是这样。但我的机器是windows,目标是某种linux。
其思想是,mail()函数在MIME-VersionContent-Type头之间放置一个新行,从而破坏了整个过程。下面是代码,尽可能简单化:

<?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" <[email protected]>
Reply-To: [email protected]
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('[email protected]', 'Testmail', $Body, $Headers) ? 'WIN' : 'FAIL';
?>

最佳答案

你可能有回车和换行。Windows使用CR+LF结束行,而Linux仅使用换行。

08-17 08:33