Mail Form

It is implemented as a cgi script that can be used in html forms and php scripts to gather data and send them to the web owner by e-mail. It has a built-in protection mechanism against spamming web crawlers.

Let the following example serve as an illustration and explanation of how it works. Suppose in your web space you have a page, simpleform.html, the content of which is this (taken from http://www.mispress.com/introcgi/cgi-lib/ex/simple-form.html and modified to suit our purposes):

<html>
<head>
<title>A simple form example</title>
</head>
<body>

<form action="/cgi-bin/mailbook.pl" method="POST">

<input type="hidden" name="htmlfile" value="simpleform.html">
<input type="hidden" name="redir" value="/your_login/confirm.html">
<H2> Pop Quiz: </H2>
What is thy name: <input name="1.name"><P>
What is thy e-address: <input name="2.addr"><P>
What is thy quest: <input name="3.quest"><P>

What is thy favorite color:
<select name="4.color">
<option selected>chartreuse
<option>azure
<option>puce
<option>cornflower
<option>olive draub
<option>gunmetal
<option>indigo2
<option>blanched almond
<option>flesh
<option>ochre
<option>opal
<option>amber
<option>mustard
</select>
<P>

What is the weight of a swallow: <input type="radio" name="5.swallow"
value="african" checked> African Swallow or
<input type="radio" name="5.swallow" value="continental"> Continental
Swallow
<P>

What do you have to say for yourself
<textarea name="6.text" rows=5 cols=60></textarea>
<P>

Press <input type="submit" value="here"> to submit your query.
</form>

<hr>
<address>Steven E. Brenner /
<a href="mailto:cgi-lib@pobox.com">cgi-lib@pobox.com</a></address>
$Date: 2025/07/31 16:35:21 $
</body>
</html>

You might wish to copy the example into your web space, and try it.

Both hidden inputs, "htmlfile" and "redir", are optional. The first is to indicate location of the file containing the form. The second is a location of your html file to be delivered as your response to succesful submission of form data. The location is either a full pathname of the file as shown above, or its full url, eg. http://www.hermes.net.au/username/confirm.html, or even a url pointing to a file on another server, eg. http://www.some.other.server/directory/file.html.

If the whole line defining "redir" is missing, a default response will be displayed, see below.

After suitably modified simpleform.html is in place, you or anybody else on the Internet can point one's browser to http://www.hermes.net.au/username/simpleform.html, fill in the form, and submit it. Then, the visitor is asked to type a 6 character code whose image appears in the browser window. This is to protect the form against various automatic web crawlers that can attempt to use it for spamming purposes. It ensures that the form is actually submitted by a real person. After submission, a response appears in the browser window. In the absence of the third input "hidden" line, the default response is:

Thank you for filling the form. Your data have been sent to webmaster@hosted.domain.com.

Otherwise, the response is taken from the file defined in the value of the third "hidden" input, "redir".

A few milliseconds after submission, you will get a message from admin, containing all the form data submitted by a click on "here". Eg.:

Date: Tue, 19 Aug 2025 17:12:17 +1000
From: iforgot@hotmail.com
To: webmaster@hosted.domain.com
Subject: data from simpleform.html

1.name: I.F.Orgot
2.e-addr: iforgot@hotmail.com
3.quest: to change my name
4.color: puce
5.swallow: continental
6.text: if only I remembered ...
filled in on remote host 203.35.8.211

The "From:" address is taken from the form data, thus allowing the use of the REPLY button of your mail program if you wish to reply. If, however, no valid e-mail address can be found in the form data, the "From:" address will be the same as the "To:" address of the message. Therefore, any reply will be sent back to you.

Mailbook.pl works not only for simpleform.html shown above, but also for any other form that you might place in your webspace provided your form includes the lines:

<form action="/cgi-bin/mailbook.pl" method="POST">
<input type="hidden" name="htmlfile" value="your_form.html"> <!-- optional -->
<input type="hidden" name="redir" value="/your_login/confirm.html"> <!-- optional -->

where your_form.html is the actual file name of your form in your web space correspondingly. Moreover, you can have more than one such form, of course with different file names. You may have noticed in the example above that the file name of the form appears in the subject field of the message sent to you, containing the form data. This is how you are informed which form the data come from.

You may wonder why non-hidden input names in the example above are 1.name, 2.quest, 3.color, etc. This is because mailbook.pl sorts all input data according to the lexicographical order of their names. If you want the same order of data in messages produced by mailbook.pl as in your form, input names should be defined in that order. If, however, you do not care about the order of data in the messages, you can name your input items any way you wish.

The last line of the message do not come from the form. It tells you the ip number of the machine from which the data have come to you. If you know something about tcp/ip, it might give you an idea about the data source.