Forum Moderators: coopster & phranque

Message Too Old, No Replies

Need Form which emails results as attachment

         

nerve

7:15 pm on Dec 27, 2004 (gmt 0)



Not sure if it's possible, but I need a form which, when submitted, sends me the form's results as an attachment. When the attached file is opened, I need it to look exactly like the form with the submitted info filled in.

Any ideas?

[edited by: jatar_k at 7:26 pm (utc) on Dec. 27, 2004]
[edit reason] no personal urls thanks [/edit]

rocknbil

1:59 am on Dec 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ahh the WYSIWYG email solution. :-) This is asked semi-daily (maybe not on msg. boards but I hear it a lot from co-workers.)

There's really no way to do the exact visual duplicate except with a PDF, and that requires a full version with plug-ins for all users who might view it.

In regular email, once encoded, the data is encoded in key-value pairs, and generally decoded as plain text. When you put plain text back into an email with no foreknowledge of how it is to be received, what fonts are going to be used to affect your output, the results can be unpredictable. You can, however, reformat it in a way that makes sense.

As for an attachment - look up the MIME:Lite module at a CPAN near you. This module makes automating attachments a breeze. It also makes it easy to output a multi-part mime type so you can deliver both plain text and HTML format, which may get you even closer to your look-alike formatting.

dmorison

2:45 am on Dec 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Any ideas?

This should be pretty straight forward; as you can create an HTML email simply including the following headers:


MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1

You will have to work out how to set the email headers using whatever method you are using to send the email - you probably do it in the same place that you set the "From:" header.

Then, your email message body simply begins with "<HTML><BODY>", contains your form HTML with the fields pre-populated with the submitted content, and ends with </HTML></BODY> just as any other HTML document.

A nice way to architect this would be to have a single function that generates the form HTML which is then used to craft both your page and the email. This would mean that you only have to make changes in one place when your form content changes.

If you've never done form to email at all, you really need to step back from this requirement, learn how to do a simple form to email first, and then look at doing this.

Hope this helps!

kaled

10:23 am on Dec 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Create a small email with the required data and structure, send it to yourself and then inspect the source code. From memory, attachment data is hex-encoded ("uuencoded") but I haven't looked at this for a long time.

Attached text data may not require encoding.

Kaled.