$to = '[email protected]';
$subject = 'Receipt';
$repEmail = '[email protected]';
$fileName = 'receipt.pdf';
$fileatt = $pdf->Output($fileName, 'E');
$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)){
$action = 'action=Receipt%20Sent';
header('Location: ../index.php?'.$action);
}
else {
$action = 'action=Send%20Failed';
header('Location: ../index.php?'.$action);
}
我一直在使用TCPDF很短的時間來從窗體生成PDF文件。它工作得很好,PHP的一部分沒有改變。現在我想將這些PDF文件發送到我的電子郵件帳戶。如何使用帶有PHP郵件功能的TCPDF
電子郵件實際上是使用這種編碼並附加PDF。問題在於,它只是一個空白的PDF,大小爲100個字節。這當然不是一個有效的PDF,也不會與表單的回覆有任何關係。
我真的不熟悉在PHP中附加文件到電子郵件和任何幫助解決這個問題將不勝感激。
更新
由於好像幾個人都在看這還是我將張貼我目前的解決方案。它涉及下載PHPMailer如下所示。我已經開始在TCPDF的輸出行。
$attachment = $makepdf->Output('filename.pdf', 'S');
SENDmail($attachment);
function SENDmail($pdf) {
require_once('phpmailer/class.phpmailer.php');
$mailer = new PHPMailer();
$mailer->AddReplyTo('[email protected]', 'Reply To');
$mailer->SetFrom('[email protected]', 'Sent From');
$mailer->AddReplyTo('[email protected]', 'Reply To');
$mailer->AddAddress('[email protected]', 'Send To');
$mailer->Subject = 'Message with PDF';
$mailer->AltBody = "To view the message, please use an HTML compatible email viewer";
$mailer->MsgHTML('<p>Message contents</p>'));
if ($pdf) {$mailer->AddStringAttachment($pdf, 'filename.pdf');}
$mailer->Send();
}
extra)on line 14 – dricket 2016-02-05 06:26:26