Linux下的PHP mail()的奇怪问题

时间:2009-02-18 20:15:12

标签: php email mime

当它“在我的机器上运行”时就是这种情况。除了我的机器是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" <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';
?>

1 个答案:

答案 0 :(得分:3)

您可能在那里有回车符和换行符。 Windows使用CR + LF结束行,但Linux仅使用换行符。

相关问题