【问题标题】:How do I attach a generated pdf by dompdf and mail it in phpmailer?如何附加由 dompdf 生成的 pdf 并将其邮寄到 phpmailer?
【发布时间】:2018-03-02 23:14:49
【问题描述】:

我正在使用 dompdf 生成 pdf,我需要将其附加到 phpmailer 并邮寄。 我们将不胜感激。

<?php
require_once("../../dompdf/dompdf_config.inc.php");

$templateFile = 'prog_report.php';
$content = file_get_contents($templateFile);
$dompdf = new DOMPDF();
$dompdf->load_html($content);

$dompdf->render();
$dompdf->stream("sample.pdf");

?>

这是 phpmailer 附件模块..

$mail->AddAttachment("images/phpmailer.gif");

我想在此处附上生成的 pdf,该 pdf 不应该保存在硬盘驱动器上。

【问题讨论】:

  • 你得到这个问题的答案了吗
  • 是的,将pdf复制到变量$pdf=$dompdf->output();然后使用以下代码将其附加到邮件中 $mail->AddStringAttachment($pdf, 'filename.pdf');
  • @Venkat : 我需要一些关于 php 的信息,我可以联系你吗?或在 FB 上找到你
  • 您可以联系我@venkatakrishnabtech@gmail.com .......或者也可以在 Fb 中使用该电子邮件 ID 搜索我

标签: php phpmailer dompdf


【解决方案1】:

磁盘上没有保存文件:

$pdfString = $dompdf->output();
$mail->addStringAttachment($pdfString, 'name file.pdf');

【讨论】:

  • 在证明答案时,请说明解决问题的原因和方法。
【解决方案2】:

首先在您的服务器中创建 pdf 文件

为什么不交换它们,首先将 pdf 创建为文件,然后将创建的文件流式传输回来?

$file_to_save = '/home/stsnew/public_html/pdf/file.pdf';
//save the pdf file on the server
file_put_contents($file_to_save, $dompdf->output()); 

然后它会附在邮件中。

【讨论】:

  • 好吧,我不希望文件保存在服务器上..单击按钮我希望 pdf 由 phpmailer 生成和邮寄。
  • 您不想附加要作为内容发送 pdf 文件的文件
  • 告诉我将其附加到邮件的确切方法?
【解决方案3】:

嗨,伙计,我使用了 fpdf 库和 php 邮件程序,它就像魅力一样工作,试试这个。

require('fpdf.php');
$filename="bookingconfirmation.pdf";
//rest of pdf code here

$pdf->Output($filename);

include "libMail/class.phpmailer.php";
$m= new Mail; // create the mail
$m->IsSMTP(); // telling the class to use SMTP
$m->Host = "mail.connectingauthors.com"; // SMTP server
$m->SetFrom("susan@connectingauthors.com");    
$m->AddReplyTo("pixelart@optonline.net");
$m->AddAddress("pixelart@optonline.net");
$m->Subject( "Connecting Authors Booking Confirmation" );
$m->MsgHTML( "HellonnPlease find attached ..." ); // set the body
$m->AddAttachment( $filename ) ;
$m->Send(); // send the mail
exit();

【讨论】:

    【解决方案4】:

    我在 DomPDF 的 wiki http://code.google.com/p/dompdf/wiki/FAQtry 上查看了常见问题解答

    $pdf = $dompdf-&gt;output();

    而不是

    $pdf = $dompdf->stream('name');
    

    【讨论】:

      【解决方案5】:

      我只是使用下面的代码自己修复了它:

      ->attach(Swift_Attachment::fromPath($pass_doc_path))
      

      它对我有用。

      非常感谢

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-21
        • 1970-01-01
        • 2017-11-01
        • 2014-04-02
        • 1970-01-01
        • 1970-01-01
        • 2011-12-18
        • 2013-06-24
        相关资源
        最近更新 更多