How to generate a PDF from a registration folder and then attach the generated file and send it by email?

Asked

Viewed 159 times

0

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

I thank you for your attention.

  • help? https://answall.com/questions/31771/como-gerar-contrato-em-pdf-utilizando-php-directly?rq=1

  • All help is welcome! Thank you very much!

1 answer

1

After the form post, mount an HTML "body" even (you don’t need to display it. Save it in a variable), and make the PDF lib of your choice convert into a valid PDF.

Personally use the mPDF for this and solves 95% of my problems (I had a recent problem with large tables and still could not heal. Plus, it’s perfect and super flexible).

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

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

After saving, I take the URL I generated there and use the Phpmailer to send the attached file. To attach something with Phpmailer, use:

$mail->AddAttachment($_SERVER['DOCUMENT_ROOT'].'/upload/pdf/'.$nomeArquivo.'.pdf);
  • 1

    Thank you very much Maykel! It was this light that I needed!! helped me a lot. Abraco!

  • If you can, mark the answer as answered! ;-)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.