php 发送带pdf附件的email 出现的是一长串字符串 请教怎么解决

WBOY
Release: 2016-06-13 12:37:09
Original
1828 people have browsed it

php 发送带pdf附件的email 出现的是一长串字符串 请问如何解决
RT,发出的email附件不是一个pdf档,而变成了一长串字符串,

我的发送email的代码如下:

function mail($mailto, $userid, $data){
    global $dsql,$cfg_adminemail,$cfg_webname,$cfg_basehost,$cfg_memberurl;
    $mailtitle = $cfg_webname.":通知";
$file=fopen("D:/xampp/htdocs/pdftemp/dsfasdf.pdf","r"); 
$fileName=$data['oid'].'.pdf';
$mimeType ="application/pdf"; 
$boundary = "nextpart_".uniqid("");  //分隔符1
$boundary2 = "nextpart2_".uniqid(""); //分隔符2

        //email头
$headers = "From: ".$cfg_adminemail."\r\nReply-To: $cfg_adminemail";
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary1\"\r\n";

        //读取文件
        $read = fread($file, filesize("D:/xampp/htdocs/pdftemp/dsfasdf.pdf")); 
//我们用base64方法把它编码 
$read = base64_encode($read); 
//把这个长字符串切成由每行76个字符组成的小块 
$read = chunk_split($read);

        //以下是mailbody正文 
$mailbody = "--$boundary1----$boundary2 
Content-type: text/plain;charset=iso-8859-1;
Content-transfer-encoding: 8bit";
    $mailbody .= '致: '.$userid.',



This is mailbody--$boundary2--';
        
        //以下是附件部分
$mailbody .="--$boundary1 
Content-type: text/html; name=$fileName 
Content-disposition: inline; filename=$fileName 
Content-transfer-encoding: 8bit
$read 
--$boundary1--";


    $status = smail($mailto,$mailtitle,$mailbody,$headers);
    setMail($mailto, $mailtitle, $mailbody, $headers, $status);
    return $status;
}

php email pdf
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!