MPDF E-mail Attachment Sends Blank PDF

前端 未结 2 1448
盖世英雄少女心
盖世英雄少女心 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:

    <?php
    require_once $swift_mailer_path.'swift_required.php';
    
    $transporter = Swift_SmtpTransport::newInstance($smtp_host, $smtp_port, $smtp_protocol)
      ->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.

    0 讨论(0)
  • 2021-01-07 05:22
    mpdf->WriteHTML($template);
    $content = $mpdf->Output($template, 'S');
    

    You are wrong at here you are not taking the object on which your data is written

    please replace below code with above to get correct result.

    $pdfdata=mpdf->WriteHTML($template);
    $content = $mpdf->Output('' , 'S');
    

    use $content in your email

    0 讨论(0)
提交回复
热议问题