PDF文件正在由tcpdf庫生成,但我不能附加到電子郵件。它發送一個空的1kb PDF文件的電子郵件。電子郵件TCPDF生成的PDF文件與PHP郵件功能
$to = '[email protected]'; $subject = 'Receipt'; $repEmail = '[email protected]'; $fileName = 'receipt.pdf'; $fileatt = $pdf->Output($fileName, 'S'); $attachment = chunk_split($fileatt); $eol = PHP_EOL; $separator = md5(time()); $headers = 'From: Sender <'.$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 .= "This is a MIME encoded message.".$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"; }
我知道它的多用PHPMailer的容易,但我需要用郵件功能來做到這一點,不使用任何圖書館。 任何幫助表示讚賞。
它不應該是$附件= chunk_split($文件名); – vodich 2013-03-27 15:36:52
你在開玩笑嗎? $ filename是用於附件的11位數字的「名稱」 – 2013-03-27 15:45:29
請在使用phpMailer等優秀庫的時候請不要使用PHP的內置'mail()'函數發送附件,這會讓您的生活變得更加輕鬆。儘管你在問題中提到了什麼,但真的沒有理由不使用它。 – Spudley 2013-03-27 15:45:54