2017-04-25 32 views
1

我正在使用dompdf来生成一个pdf($ output = $ dompdf-> output();),我需要将它附加到phpmailer并将它邮寄给它...如何使用sendgrid mail api将dompdf生成的pdf附加到邮件中?

而我使用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); 

} 

我如何通过电子邮件

$产值任何方式来传递$输出文件路径$?

回答

2

保存的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?

相关问题