2014-04-15 120 views
0

我是新来的php。我需要发送电子邮件与pdf附件。我可以发送附件的电子邮件。但无法打开PDF。我得到这样的一些错误用php附件发送电子邮件,内容为php

“Acrobat无法识别'file_name',因为它不是受支持的文件类型,或者是因为文件已损坏(例如,它是作为电子邮件附件发送的,而不是正确解码)...“

如果有人能帮我解决这个问题,那会很好。谢谢!

这里是我的代码:

$to = '[email protected], ' . $Email; 
$subject = 'ABC :: Admission Form Details'; 
$repEmail = '[email protected]'; 

$fileName = 'ABC-Admission.pdf'; 
$fileatt = $pdf->Output($fileName, 'E'); 
$attachment = chunk_split($fileatt); 
$eol = PHP_EOL; 
$separator = md5(time()); 

$headers = 'From: Principal abc <'.$repEmail.'>'.$eol; 
$headers .= 'MIME-Version: 1.0' .$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\""; 

$message = "--".$separator.$eol; 
$message .= "Content-Transfer-Encoding: 7bit".$eol.$eol; 
$message .= "Thanks for filling online application form. Your online admission registration number is E0000". mysql_insert_id() . "." .$eol; 

$message .= "--".$separator.$eol; 
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol; 
$message .= "Content-Transfer-Encoding: 8bit".$eol.$eol; 

$message .= "--".$separator.$eol; 
$message .= "Content-Type: application/pdf; name=\"".$fileName."\"".$eol; 
$message .= "Content-Transfer-Encoding: base64".$eol; 
$message .= "Content-Disposition: attachment".$eol.$eol; 
$message .= $attachment.$eol; 
$message .= "--".$separator."--"; 

if (mail($to, $subject, $message, $headers)){ 
echo "Email sent"; 
} 

else { 
echo "Email failed"; 
} 

回答

0

试试这个:

$attachment = chunk_split(base64_encode($fileatt)); 

而不是

$attachment = chunk_split($fileatt);