> webform > mailform

about mailform

Important Notice. To increase security mailform is now HTTPS only. Your own pages do not need to be https, but in your own web form's <form> tag, the 'action' attribute should be set to ""

Mailform allows you to set up simple forms or questionnaires on the web and have the results mailed back to you. It is intended largely for tutorial use and so is functional, but does not include refinements such as allowing the web user to preview or edit the form before confirming it.

You set up the questionnaire or form on your web site, then link to a special script on meandeviation. When the web user fills in the form and submits it, the form contents are mailed back to you.

Because the script runs on the meandeviation server you can use this script even if your own web provider does not allow you to run scripts. All you need is somewhere to put a normal web page.

If you want to make write your own scripts on a web server try the PHP tutorial on this site.

using mailform

The simplest way to use mailform is to copy one of the two html pages (look at them now):


These are identical except the "using get" version uses the HTTP 'GET' method for passing form variables. If you are not used to using forms you may want to experiment with this first on a simple form to see how the form works and then move to the 'POST' version (testmailform.php).

View the pages and use your browser's 'save as HTML' feature to save the pages. In my version of IE this is File > Save As ... which gets you a dialogue box. You then have to set the option "HTML Source" on the dialogue box and select where you want it saved on your machine and your chosen file name.

Use the instructions below to edit the pages and then either open them locally to test or upload to your own web space. You DO NOT need to have PHP scripts enabled on your own web space, as this all happens on the meandeviation server. Note: if viewing locally you need to be web-connected for the script to run.

Alternatively (for web experts) just make any web form you like including any standard form tags (excluding file upload). Avoid using the field names "mailto" or "thanksurl" as these are used specially by the script.. You must then include two hidden fields (see below) and set the "action" of the form to "".

looking at the test pages and editing them

If you look in the source of the test form pages (use View > Source or the equivalent on your browser) you will see a standard web form (enclosed in <form> </form> tags).

You can freely edit the HTML before and after the form to add your own headers, explanations, etc. To encourage people to complete your form it is wise to include something that explains clearly what the information is required for, how you intend to use it, privacy policy etc. Also be aware that if you are collecting any personal information you will need to satisfy any national legal requirements such as the Data Protection Act in the UK.

Look now at the first three lines of the form:

<form method="POST"
<input type="hidden" name="mailto"
value="your@email.address"><!-- ...  -->
<input type="hidden" name="thanksurl"
... -->

The 'action' attribute of the <form> tag is set to "". Leave this as it is. The 'method' is either 'POST' or 'GET' depending on which version of the page you are looking at.

Following this are two lines that you must edit. These are 'hidden' fields - web form fields that are sent back to the server when the form is submitted but which don't appear on the form as submitted.

The first hidden field (name="mailto") is the mail address it which the completed form will be sent. Substitute your own email address in the 'value' field.

VERY IMPORTANT - enter your email address carefully, if you get it wrong the completed form will be lost (or sent to someone else!!)

The second hidden field (name="thanksurl") is the 'thank you' page that is shown to the user of the form after it has been successfully submitted. You should design your own thank you page and put the url of it here instead of the default one.

Following the two hidden fields are some lines of html including two standard web form fields: a text field (name="name") and a pull down list (name="title").

     <input type="text" name="name">
     <select name="title">
       <option selected>Prof</option>

These are what generate the actual form fields shown to the user:

You can change this section to include any fields you want in your form or questionnaire. As you can see it is possible to use pull down fields, radio buttons and checkboxes as well as text fields. You can of course also remove the two example fields 'name' and 'title' if you don't require these.

Note on using checkboxes: if you are use checkboxes either give them different names (e.g. 'interest1', 'interest2' - see example in about showform) or add '[]' after each checkbox name in the html code (e.g. 'interest[]'). If you use the same name for all the checkboxes and the user selects several items, then only one of the selected checkbox values will be mailed to you.

Finally look at the end of the form

     <input type="submit" name="Submit"

You must include a 'submit' button in your form otherwise the user can't send it. However, the button can be called something else such as "Go" or "Done" if you prefer, or you can submit the form using a clickable image map.

the email you receive from mailform

When the user completes the form and it is submitted the mailform.php script creates an email containing all the form fields and sends these in an email to you. The mail will look something like the following:

To: your@email.address
Subject: Form Mail from
From: "Form Mail" <>

name: Alan Dix

title: Prof

Submit: Submit

Of course this mail is based on the test form with only the 'name' and 'title' fields (and submit button), your mail will have whatever form fields you have added.

Make a copy of the form pages, edit them, add your own mail address and try filling it out and submitting it to see what it is like yourself. But do remember to set the hidden 'mailto' field correctly otherwise you will get no email!!

Note too that the mail you will be sent will be 'From' the form_mail agent, not the person filling in the form. Please make sure you, or whoever is receiving the mails, realises this and extracts the right email address from the fields on your form. DO NOT press your mail clent's 'reply' button or the mail will go back to formmail and get lost! Alan Dix © 2002,2019