为什么我们通过电子邮件发送的pdf文件不能打开? [英] php Why pdf which we send on email not open?

查看:57
本文介绍了为什么我们通过电子邮件发送的pdf文件不能打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

            $NameFile = '15_10_2014_.pdf';
            $File = './TEMP/15_10_2014_.pdf';
            $to = 'test2@test.com';
            $From = "test@test.com";

        $EOL = "
"; 
        $boundary     = "--".md5(uniqid(time()));
        $message = "
        <p>TEXT TEXT TEXT</p>
        ";
        $subject= '=?utf-8?B?' . base64_encode('Счет на оплату') . '?=';

        $headers    = "MIME-Version: 1.0;$EOL";   
        $headers   .= "Content-Type: multipart/mixed; boundary="$boundary"$EOL";  
        $headers   .= "From: $From
Reply-To: $From
";  

        $multipart  = "--$boundary$EOL";   
        $multipart .= "Content-Type: text/html; charset=utf-8$EOL";   
        $multipart .= "Content-Transfer-Encoding: base64$EOL";   
        $multipart .= $EOL;
        $multipart .= chunk_split(base64_encode($message));   

        $multipart .=  "$EOL--$boundary$EOL";   
        $multipart .= "Content-Type: application/octet-stream; name="$NameFile"$EOL";   
        $multipart .= "Content-Transfer-Encoding: base64$EOL";   
        $multipart .= "Content-Disposition: attachment; filename="$NameFile"$EOL";   
        $multipart .= $EOL; 
        $multipart .= chunk_split(base64_encode($File));   

        $multipart .= "$EOL--$boundary--$EOL";   

        if(!mail($to, $subject, $multipart, $headers)){
            $content = $this->return_error_p('Mail not send');
        }
        else{
            $content = $this->return_true_p('Mail send');
        }
结果,我们收到了一封带有pdf附件的电子邮件,但该pdf文件没有打开。打开文件时,我们收到错误消息:"不支持文件格式,或者该文件是通过电子邮件发送的,但未正确解码。"

请告诉我哪里出错?

推荐答案

您需要获取内容文件:

$openfile = fopen($File, "rb");
$data = fread($openfile,  filesize( $filename ) );
fclose($openfile);
$File = $data;

享受!

这篇关于为什么我们通过电子邮件发送的pdf文件不能打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆