【问题标题】:How do I attach a generated pdf by dompdf into mail using sendgrid mail api?如何使用 sendgrid 邮件 api 将 dompdf 生成的 pdf 附加到邮件中?
【发布时间】:2017-09-21 22:05:38
【问题描述】:

我正在使用 dompdf 生成一个 pdf ( $output = $dompdf->output(); ),我需要将它附加到 phpmailer 并邮寄......

我正在使用 sendgrid 作为邮件服务...

function sendEMailwithAttachment($mail_type, $mail_variable = array(), $subject, $from, $mailto, $username, $fileName, $filePath) { 

    $to = new SendGrid\Email($username, $mailto);
    $content = new SendGrid\Content("text/html", $message);
    $file = $filePath;
    $file_encoded = base64_encode(file_get_contents($file));
    $attachment = new SendGrid\Attachment();
    $attachment->setContent($file_encoded);
    $attachment->setType("application/text");
    $attachment->setDisposition("attachment");
    $attachment->setFilename($fileName);

    $mail = new SendGrid\Mail($from, $subject, $to, $content);
    $mail->addAttachment($attachment);

}

如何在电子邮件中传递 $output 值

有什么方法可以将 $output 作为 $filePath 传递吗?

【问题讨论】:

    标签: php codeigniter email sendgrid dompdf


    【解决方案1】:

    将您的 PDF 文件保存在磁盘中:

    $output = $dompdf->output();
    file_put_contents('output.pdf', $output);
    $fileName = 'output.pdf';  // Pass this variable to sendEMailwithAttachment function
    

    然后将文件路径传递给邮件发件人。发送后从服务器中删除您的 pdf 文件。

    来源:how to save DOMPDF generated content to file?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-18
      • 2017-04-12
      • 2017-08-17
      • 1970-01-01
      • 1970-01-01
      • 2018-12-23
      • 2014-04-02
      相关资源
      最近更新 更多