MPDF E-mail Attachment Sends Blank PDF

前端 未结 2 1470
盖世英雄少女心
盖世英雄少女心 2021-01-07 04:33

I have successfully generated a PDF using mpdf, which I have verified by downloading the PDF. However, when I send the PDF as an e-mail attachment I receive a blank PDF with

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-07 05:12

    If you can use swiftmailer, you can attach a MPDF generated PDF to the email, quite easily as follows:

    setUsername($smtp_username')
      ->setPassword($smtp_password');
    
    $mailer = Swift_Mailer::newInstance($transporter);
    
    $message = Swift_Message::newInstance('Email Subject')
      ->setFrom(array($from_email => $from_name))
      ->setTo($to_email)
      ->setBody($email_body);
    
    $attachment = Swift_Attachment::newInstance($mpdf->Output($pdf_path, "S"), $pdf_file_name, 'application/pdf');
    $message->attach($attachment);  
    
    $message->setContentType("text/html");
    
    $result = $mailer->send($message);
    ?>
    

    Here is the Reference.

提交回复
热议问题