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";
}