How to generate a PDF from a registration form and then attach the generated file and send it by e-mail?

0

I need to generate a PDF at the end of filling out a form and then attach it and send it via email. I need a light because I have no idea what tools to use!

Thank you very much for your attention.

    
asked by anonymous 29.01.2018 / 16:57

1 answer

1

After the POST of the form, put a "body" in HTML itself (you do not need to display it. Save to a variable), and make the PDF lib of your choice convert into a valid PDF.

I personally use mPDF for this and solve 95% of my problems (I had a recent problem with large tables and still could not heal In fact, it's perfect and super flexible.)

After that, I write the PDF to the server. In the case of MPDF, I use:

$mpdf->Output($_SERVER['DOCUMENT_ROOT'].'/upload/pdf/'.$nomeArquivo.'.pdf', 'F');

Once it's saved, I'll take the URL I generated there and use PHPMailer to send the attached file. To attach something with PHPMailer, I use:

$mail->AddAttachment($_SERVER['DOCUMENT_ROOT'].'/upload/pdf/'.$nomeArquivo.'.pdf);
    
29.01.2018 / 20:29