问题
I am generating a pdf file on the fly without saving it to the disk with:
$attachment = $this->pdf->Output('e-tickets.pdf', 'S');
According to TCPDF
this should return a string containing the pdf
file.
But sending it with PHPMailer
results in a corrupt file:
$mail->AddStringAttachment($attachment, 'e-tickets.pdf', 'base64', 'application/pdf');
I tried the following alternatives (and all possible combinations):
$attachment = $this->pdf->Output('e-tickets.pdf', 'E');
$mail->AddStringAttachment($attachment, 'e-tickets.pdf');
Nothing resulted in a working pdf
file.
The file is not empty (it has a filesize) and when I use the D
option in TCPDF
the file is downloaded fine.
All other topics on Stackoverflow did not help me. they are all quite old and I am guessing using an older version.
Any suggestions?
回答1:
I solved it myself. It was a stupid mistake really
I use $this->pdf->Output('e-tickets.pdf', 'E');
in a class.
I changed it to return $this->pdf->Output('e-tickets.pdf', 'E');
and it solved the issue.
Fresh day, fresh look at things can help.
Thank you for your help
回答2:
Have you tried:
$attachment = $this->pdf->Output('e-tickets.pdf', 'E');
$attachment = chunk_split($attachment);
$mail->AddStringAttachment($attachment, 'e-tickets.pdf');
来源:https://stackoverflow.com/questions/46267433/send-tcpdf-generated-pdf-with-phpmailer