Wie zu verwenden TCPDF mit PHP mail-Funktion

$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);
}

Habe ich mit TCPDF, für eine kurze Zeit nun um PDF-Dateien generieren von Formen. Es funktioniert ganz gut, und dieser Teil des PHP hat sich nicht geändert. Jetzt will ich senden Sie diese PDF-Dateien an meine E-Mail-Konto.

Die E-Mail tatsächlich funktioniert mit dieser Codierung und anfügen einer PDF-Datei. Das Problem ist, dass es einfach eine leere PDF-Datei auf grobe 100 bytes groß. Das ist natürlich keine gültige PDF noch hat es etwas zu tun mit den Antworten aus dem Formular.

Ich bin wirklich nicht vertraut mit dem Anhängen von Dateien an eine E-Mail in PHP und jede Hilfe bei der Lösung dieses Problems würde sehr geschätzt werden.

Update

Da es scheint, wie einige Leute diese trotzdem werde ich nach meiner aktuellen Lösung. Es beinhaltet den Download PHPMailer, wie unten vorgeschlagen. Ich habe angefangen, am line-Ausgang für 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 ) auf Linie 14

InformationsquelleAutor foochow | 2012-07-20

Schreibe einen Kommentar