2017-04-25 68 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?

相關問題