当它“在我的机器上工作”时就是这种情况.除了我的机器是Windows,目标是某种Linux.
这个想法是mail()函数在MIME-Version和Content-Type标头之间放置换行符,从而破坏了整个过程.这是尽可能简化的代码:
$HTMLPart = chunk_split(base64_encode('
Test.'));$PlaintextPart = chunk_split(base64_encode('>>> TEST <<
$Headers =<<
From: "My Test"
Reply-To: my@mail.com
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="9-1410065408-1410065408=:27514"
AKAM;
$Body =<<
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';
?>
解决方法:
您可能在这里有回车和换行符. Windows使用CR LF结束行,但是Linux仅使用换行符.
标签:email,mime,php
来源: https://codeday.me/bug/20191210/2103542.html