为什么邮件附件在php中发送编码内容而不是PDF文件

时间:2016-07-06 06:04:20

标签: php html email

你好最近我正在处理php邮件附件,但是当我将附件发送给某人的电子邮件时,我遇到了一个问题,它会显示为

            This is my first mail.Content-Type: application/octet-stream; name="PankajChandwani.pdf"
        Content-Transfer-Encoding: base64
        Content-Disposition: attachment; filename="PankajChandwani.pdf"

        JVBERi0xLjQKJaqrrK0KNCAwIG9iago8PAovQ3JlYXRvciAoQXBhY2hlIEZPUCBWZXJzaW9uIDEu
        MSkKL1Byb2R1Y2VyIChBcGFjaGUgRk9QIFZlcnNpb24gMS4xKQovQ3JlYXRpb25EYXRlIChEOjIw
        MTYwNjIzMDY0OTM3WikKPj4KZW5kb2JqCjUgMCBvYmoKPDwKICAvTiAzCiAgL0xlbmd0aCAxMSAw
        IFIKICAvRmlsdGVyIC9GbGF0ZURlY29kZQo+PgpzdHJlYW0KeJydlndYU+cex99zTvZgJCFsCHuG
        pUAAkRGmgAzZohCSAAESICQM90BUsKKoyFIEKYpYsFqG1IkoDori3g1SBJRarOLC0USep/X29t7b
        2+8f53ye3/v7vef9jfd5DgCkgEyuMBdWAUAokogj/L0ZsXHxDOwAgAEeYIA9ABxubrZXWFgwkCvQ
        l83IlTuBf9GrmwBSvK8xFXuB/0+q3GyxBAAoTM6zePxcrpyL5JyZL8lW2CflTEvOUDCMUrBYfkA5
        ayg4dYatP/vMsKeCeUIRT86Rcs7mCXkK7pXzhjwpX86IIpfiPAE/X87X5WycKRUK5PxGESvkc+Q5

编码内容这是我在php中的邮件附件代码

$path = get_home_path();
$filename='Pankaj.pdf'; 
 $file = $path.'wp-admin'.'/'.$filename;
 //print_r($file);
    $file_size = filesize($file);
    $handle = fopen($file, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
    $content = chunk_split(base64_encode($content));
$to = $_REQUEST['email'];
$subject = 'Test email'; 
$message = "Hello World!\n\nThis is my first mail."; 
 $message .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
    $message .= "Content-Transfer-Encoding: base64\r\n";
    $message .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
    $message .= $content."\r\n\r\n";
$headers = "From: ankits8@gmail.com\r\nReply-To: ankits8@gmail.com";
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed"; die;

我无法估计出错的地方请找出错误并帮助谢谢。

0 个答案:

没有答案