So I Have a form that will send out emails that correspond to how they filled the form. I have to take some information that was filled in the form and put it in a HTML form to send in a email which is done in php.
My question is, is there anyway to turn that form into a attachable file that could just be added to the mail function and sent instead?
Thank you for your time!
Yes, you can transform your HTML form into a… HTML page (using HTML tokens manually, or maybe something like TCPDF?), and save it to a temporary disk file, then attach it to the outgoing email. Of course, your mail function must support attachments! (If it doesn’t, use a different mailer functions – there’s many of them).
You can do it quickly by preparing the form manually and replacing the text fields with something like
{{ Name }}.Then just run a
str_replaceon thefile_get_contents()of your template and save the results in a temporary file:In just the same way you can prepare a Word document, save it as RTF (which is ASCII readable), and attach the file with .doc extension — most word processors will open it automatically.
If you want to send a PDF file (using TCPDF, FPDF, etc.), it’s a bit more complicated but not too much.