CGI: mail_answer.pl

Introduction This CGI is used to format nicely and e-mail the content of an HTML form. Quick setup Create an HTML form with the "METHOD" POST and the "ACTION" /cgi-bin/mail_answer.pl. Name each fields of your form by a number, followed by a ".", followed by the name of the field. When the form is submited, you will receive a mail containing the name of each field, followed by its content. The fields will be printed in the order of their number. Example : 01.Name or 02.Address Finaly, your form must contain the following fields with pre-defined values :
Field nameField value
F_subjectSubject of the mail
F_mailtoAddress e-mail where to send the mail
F_answerURL of the page to display after the form is submited

Full example

<HTML> <HEAD> <TITLE>My form</TITLE> <SCRIPT LANGUAGE="JavaScript"> function open() {return true;} </SCRIPT> </HEAD> <BODY> <CENTER><H1>A simple form</H1></CENTER> <FORM METHOD=POST ACTION="/cgi-bin/mail_answer.pl"> Enter your name : <INPUT TYPE="TEXT" NAME="01.Name"><BR> Enter your e-mail : <INPUT TYPE="TEXT" NAME="02.E-mail"><P> <INPUT TYPE="SUBMIT"><P> <!-- Set the needed fields --> <INPUT TYPE="HIDDEN" NAME="F_mailto" VALUE="user@my-email.com"> <INPUT TYPE="HIDDEN" NAME="F_subject" VALUE="Form result"> <INPUT TYPE="HIDDEN" NAME="F_answer" VALUE="http://my.domain.com/thanks.html"> </FORM> <HR> </BODY> </HTML>
Details
This script take the value from an HTML form page and use those values to format a mail. The mail is then sent to an address. The following hidden field must be defined in the HTML form : F_mailto = E-mail address to which the mail should be sent The following field may (or not) be defined in the HTML form : F_header = Name of a text file to add at the begining of the mail F_footer = Name of a text file to add at the end of the mail F_answer = Name of an HTML page to display as result of this script F_subject = Subject of the mail Other field need to be one of the following format : 1) $\S+ (a dollard sign followed by any characters) 2) \d+[FLAG]*\..+ (Some digit followed by one or more FLAG characters followed by a ".", followed by one or more chars. The meaning of those value is the following : <field number>[<formating flag>].<title to print> The formating flags should be one of more of the following : T = don't print the Title f = Force the value of the field on the same line as the title b = force a line Break after the title N = Don't print a Newline after the value n = Force an extra Newline after the value s = Field Separator. The next chars will be used to separate the values Field of type 1) are variable. If the same name appears in the answer HTML form (including the "$"), it will be substitued by the value of the field. Field of type 2) will be printed, in order of there <field number> in the mail. The value of the field is formated based on the <formating flag> value. The default is to print the <title to print> followed by the value of the field on the same line if the length of the whole line isn't larger than 80 chars. If it's larger, the value will be displayed alone one a new line. Each couple of title/value is put on a new line. Example : 1) Fields name : 01.Name Value : Stettler 02.Forname Value : Yann 03.Address Value : Gide 6 04.Comments Value : Hello world Will give a mail that look like : Name : Stettler Forname : Yann Address : Gide 6 Comments : Hello world 2) Fields name : 01N.Name Value : Stettler 02T.Forname Value : Yann 03n.Address Value : Gide 6 04b.Comments Value : Hello world Will give a mail that look like : Name : Stettler Yann Address : Gide 6 Comments : Hello world 3) Fields name : 01TNs;.Name Value : Stettler 02TNs;.Forname Value : Yann 03TNs;.Address Value : Gide 6 04TNs;.Comments Value : Hello world Will give a mail that look like : Stettler;Yann;Gide 6;Hello world;