Discussion Locked

CGI output to mail in html format

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have created a form for my site visitors for requesting product brochures. I have also created the cgi/perl parsing script. Now, in that script, I have a 'thankyou' page that is a table with the response to what the visitor has requested. I also want to email the same form to a particular person in the company to handle fulfulling the requests. I can do that, but, the email message when opened is the html mark-up, the the form itself. Consequently, it is difficult to read, so it is not yet being used. How do I get the email message to show the rendered html, not the html mark-up?

7 replies

by steved

Simply include the following email header:

Content-Type: text/html; charset=iso-8859-1

by shanghai sam

That still hasn't helped. I just don't see what I am doing wrong. I have 3 books and read many web sites and it looks right. I have no problem getting the html formatted table to show on the screen, but for the life of me I can't get it to send properly through email, I keep getting the html code, not the formatted table.

by steved

Have you looked at all the email headers that are actually being created? Is there another Content-Type header there that might conflict with the text/html one? For instance text/plain? In what order do the headers appear? Is there a Mime-Version header? If not, you may have to include something like "Mime-Version: 1.0".

The headers are the one and only factor that governs how the email client will interpret the message body. The problem has to be there. Look at the actual headers in your generated messages and compare them to those in an HTML format message that is being interpreted correctly. Then adjust yours to match.

Good luck!

Steve Diamond

by chipw

That helps alot. Now, forgive me if this is considered too basic, but how do I add the two needed headers - MIME-version and Content-type? Are they added to the cgi script? I am just learning this perl/cgi programing, and have 3 books and they seem to ignore the email options, must be covered in the advanced books.
PS,
what's up with the rating answers thing? I was going to hit the acceptable option then got a warning that I would have to close this question, which I wasn't ready to do yet.

by steved

Yes, you add the headers in your cgi script. I'll be a little hazy on the details because it's years since I've used Perl like this, but here's the basic idea. You're already adding email headers to your message when your script outputs lines like "Subject: my subject" followed by a newline character. You just need to add an additional line or lines of script to generate the other headers in a similar way. Either right before or right after the Subject line ought to work fine.

Regarding yourPS, I don't really know. I haven't asked any questions here, just posted answers. My impression is that the system is quite inflexible. I know of instances where questioners intended to award points but ended up closing the question and rejecting all the answers. I hope you won't let that happen to this one! :-)

SMD

This discussion is closed to new replies.