Send FPDF document with PHPMailer;

前端 未结 2 1549
野的像风
野的像风 2021-02-10 11:27

I am currently trying to generate a pdf with FPDF and then send it in an email with PHPMailer. I know that the PHPMailer functionality is working, and I can create the pdf. But

相关标签:
2条回答
  • 2021-02-10 11:44

    If you need to save file and send, use this.

       $file = basename("test");    //create file
        $file .= '.pdf';    //change extension of file to .pdf
        $pdf->Output($file, 'F');   //save file
      ..... 
        $mail->AddAttachment("test.pdf");   //add attachment
    

    take care of file location.

    0 讨论(0)
  • 2021-02-10 11:54

    You just need to fix your permissions. If FPDF can't write the file, then there's nothing for PHPMailer to send, so of course it won't work.

    Alternatively you can render to a string and attach that instead - this way it doesn't need to write a file:

    $pdfdoc = $pdf->Output('', 'S');
    ...
    $mail->addStringAttachment($pdfdoc, 'my-doc.pdf');
    
    0 讨论(0)
提交回复
热议问题