2014-04-15 3 views
0

PHP를 처음 접했습니다. pdf 첨부 파일이있는 이메일을 보내야합니다. 첨부 파일이있는 이메일을 보낼 수 있습니다. 그러나 pdf를 열 수 없습니다. 이 오류가 발생합니다.php에서 pdf 첨부 파일을 전자 메일로 보냅니다.

"지원되지 않는 파일 형식이거나 파일이 손상 되었기 때문에 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($fileatt); 

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

을 여기

내 코드입니다
관련 문제