php – 如何将TCPDF生成的pdf作为Swiftmailer附件发送
发布时间:2020-12-13 18:15:31 所属栏目:PHP教程 来源:网络整理
导读:我已经尝试了几种解决方案,最接近(对我来说)应该是这样的: $file = $pdf-Output('','E');$message-attach(Swift_Attachment::newInstance($file,'name.pdf','application/pdf')); $pdf是TCPDF的一个实例,$message是Swift_Message的一个实例. 使用上面的电子
我已经尝试了几种解决方案,最接近(对我来说)应该是这样的:
$file = $pdf->Output('','E'); $message->attach(Swift_Attachment::newInstance($file,'name.pdf','application/pdf')); $pdf是TCPDF的一个实例,$message是Swift_Message的一个实例. 我的问题是:如何将TCPDF生成的pdf作为Swiftmailer附件发送而不将文件保存到服务器并在发送电子邮件后将其删除. Here是TCPDF输出方法文档的链接,也许有人可以看到我错过的东西.
我正在使用这样的东西,它正在工作.对于PDF内容,我使用的是PDF库中最简单的示例之一.
[...] $pdf_as_string = $pdf->Output('','S'); // $pdf is a TCPDF instance [...] $transport = Swift_MailTransport::newInstance(); // using php mail function $message->setTo(array( "client@customdomain.com" => "Main Email","client@publicdomain.com" => "Secondary Email" )); $message->setSubject("This email is sent using Swift Mailer"); $message->setBody("You're our best client ever."); $message->setFrom("developers@mydomain.com","Developers United"); $attachment = Swift_Attachment::newInstance($pdf_as_string,'my-file.pdf','application/pdf'); $message->attach($attachment); [...] 也许这个答案有点晚,因为我使用的是swiftmailer v4_3_0和TCPDF v6_0_002.但以防万一是值得的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |