PHP邮件- Microsoft Outlook不能正确显示附加内容


PHP Mail- Microsoft Outlook does not show attached content correctly

我使用以下PHP代码的电子邮件与xyz.txt文件附件。除了Microsoft Outlook之外,所有的电子邮件客户端都可以正确地看到文件内容,但是对于Outlook客户端,而不是实际的文件内容,电子邮件正文文本被打印在附件文件中,即。"你好,2015年10月1日的测试文件 "。

我尝试了不同的boundary='"PHP-alt-$uid'",但没有运气。

任何帮助都将是非常感激的。

File xyz.txt include =>

test10637 | 202.00 | | | 10637测试

test10637 | 202.00 | | | 10637测试

    $myfile    = 'xyz.txt';
    $file_size = filesize($myfile);
    $handle    = fopen($myfile, "r");
    $content   = fread($handle, $file_size);
    $to        = "mahesh@gmail.com";
    fclose($handle);
    $content = chunk_split(base64_encode($content));
    $message = "Hi, 'nTest file for " . date("jS 'of F Y",strtotime('yesterday')); // Hi, Test file for 1st of October 2015
    $uid = md5(uniqid(time()));
    $header = "From: TestMail <raj@gmail.com>'r'n";
    $header .= "MIME-Version: 1.0'r'n";
    $header .= "Content-Type: multipart/mixed; boundary='"" . $uid . "'"'r'n";
    $header .= "This is a multi-part message in MIME format.'r'n";
    $header .= "--" . $uid . "'r'n";
    $header .= "Content-type:text/plain; charset=iso-8859-1'r'n";
    $header .= "Content-Transfer-Encoding: 7bit'r'n";
    $header .= $message . "'r'n";
    $header .= "--" . $uid . "'r'n";
    $header .= "Content-Type: application/octet-stream; name='"Testfile.txt'"'r'n";
    $header .= "Content-Transfer-Encoding: base64'r'n";
    $header .= "Content-Disposition: attachment; filename=".$myfile."'r'n";
    $header .= $content . "'r'n";

    $send =     mail($to, 'Test Subject', $message, $header);

使MIME消息多部分/混合并添加两个部分:一个文本/纯文本用于消息主体(可以为空)和实际附件。