Email PDF Attachment with PHP Using FPDF

前端 未结 4 2147
悲哀的现实
悲哀的现实 2020-12-04 10:40

I want to email a PDF as an attachment that was created using FPDF. My code looks like this, but the attachment never comes through.



        
4条回答
  •  清歌不尽
    2020-12-04 10:57

    I think you have a superfluous command there. You are using the string variant of the Output() command:

    $doc = $pdf->Output('test.pdf', 'S');
    

    Then you are performing a file_get_contents() on it:

    $attachment = chunk_split(base64_encode(file_get_contents($doc)));
    

    It is not a file, it is a file in a string, as file_get_contents() would return if $doc was a filename.

    Just reduce that down to:

    $attachment = chunk_split(base64_encode($doc));
    

    Then see if any more errors occur.

提交回复
热议问题