Php 如何使用sendgrid邮件api将dompdf生成的pdf附加到邮件中?

Php 如何使用sendgrid邮件api将dompdf生成的pdf附加到邮件中?,php,codeigniter,email,sendgrid,dompdf,Php,Codeigniter,Email,Sendgrid,Dompdf,我正在使用dompdf生成一个pdf($output=$dompdf->output();),我需要将它附加到phpmailer并将其发送出去 我正在使用sendgrid作为邮件服务 function sendEMailwithAttachment($mail_type, $mail_variable = array(), $subject, $from, $mailto, $username, $fileName, $filePath) { $to = new SendGrid\E

我正在使用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 value


是否可以将$output作为$filePath传递?

将PDF文件保存在磁盘中:

$output = $dompdf->output();
file_put_contents('output.pdf', $output);
$fileName = 'output.pdf';  // Pass this variable to sendEMailwithAttachment function
然后将文件路径传递给邮件发件人。发送后,从服务器中删除pdf文件

资料来源: