tcpdf 库正在生成 PDF 文件,但我无法将其附加到电子邮件中。它发送带有空的 1kb PDF 文件的电子邮件。
$to = 'receiver@gmail.com'; $subject = 'Receipt'; $repEmail = 'info@gmail.com'; $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 更容易,但我需要使用邮件功能来完成它并且不使用任何库。任何帮助表示赞赏。