邮件pdf附件导致文件损坏

时间:2015-03-02 16:03:03

标签: php email pdf smtp email-attachments

我遇到邮件问题pdf附件导致文件损坏。当我们点击附件时“Adobe Reader无法打开xx.pdf,因为它不是受支持的文件类型,或者因为文件已损坏(例如,它是作为电子邮件附件发送而未正确解码)”错误消息显示。以下是我的电子邮件附件代码。

$companyinfo = "xxxx";
 $ccinfoges = "test";
 $message = "test message";
include("test/mpdf/mpdf.php");
        $mpdf=new mPDF();   
        $mpdf->ignore_invalid_utf8 = true;
        $stylesheet = file_get_contents('appstyle_pdf.css');

        $mpdf->WriteHTML($stylesheet,1);
        $mpdf->WriteHTML($output);


        $comname = preg_replace("/[^A-Za-z0-9]/","",$_POST['company']);  

        $name = $dirname.str_replace(" ","-",$comname)."_".$time_stamp.".pdf";        
        $mpdf->Output($name,"F"); 
        $file = $name;
        $crlf = "\n";

        $filename = basename($file);
        $file_size = filesize($file);
        $content = chunk_split(base64_encode(file_get_contents($file))); 
        $uid = md5(uniqid(time()));

        $headers = "\r\n"
              ."MIME-Version: 1.0\r\n"
              ."Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"
              ."This is a multi-part message in MIME format.\r\n" 
              ."--".$uid."\r\n"
              ."Content-type:text/plain; charset=iso-8859-1\r\n"
              ."Content-Transfer-Encoding: 7bit\r\n\r\n"
              .$message." 
              ".$companyinfo." 
              ".$ccinfoges."\r\n\r\n"
              ."--".$uid."\r\n"
              ."Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"
              ."Content-Transfer-Encoding: base64\r\n"
              ."Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"
              .$content."\r\n\r\n"
              ."--".$uid."--";
    mail($testmail, $subject, "$message \f $companyinfo $ccinfoges", $headers);

将附件发送到Gmail时,其工作正常,某些域pdf文件已损坏。我们正在使用Windows服务器。可能会发生什么?有什么帮助吗?

0 个答案:

没有答案