开发者

PHPForm Generate PDF Send to Email

开发者 https://www.devze.com 2023-02-09 18:17 出处:网络
I\'m a beginner in PHP I was wondering if this is easy to do or if i\'d have to outsource this to a programmer -

I'm a beginner in PHP I was wondering if this is easy to do or if i'd have to outsource this to a programmer -

Basically when a user fills in the PHP Form and submits it I need this to generate as a PDF which will then email/attach to MY email and NOT the user who submitted this form.

I have looked at tcpdf, fpdi but i dont think any of those scripts allow me to do this specifically as from what i heard it generates a download link for the user, and that is not what i need.

If anyone can help me it woul开发者_JAVA百科d be greatly appreciated.

Regards Tom


You can use FPDF to create a PDF from your data and use FPDF's Output method which can also returns the generated PDF as a string. So you can take that, encode it as Base64 and create a multi-part message to send the .pdf as an attachment to your inbox.

Here is code copy-pasted from Minimal FPDF tutorial (http://www.fpdf.org/en/tutorial/tuto1.htm )

<?php
require('fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont( 'Arial', 'B', 16 );
$pdf->Cell( 40, 10, 'Hello World!' );

//documentation for Output method here: http://www.fpdf.org/en/doc/output.htm
$attach_pdf_multipart = chunk_split( base64_encode( $pdf->Output( '', 'S' ) ) );

Now use the default mail() function and create a multi-part message and use these headers for attaching the file to your message.

$msg .= "Content-Type: application/octet-stream; name=\"attachment.pdf\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: attachment\r\n";
$msg .= $attach_pdf_multipart . "\r\n";

(assuming you had already defined the required mail headers, multi-part boundary, etc in the $msg string).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号