Creating HTML to Email Forms

Sending email to the owner of the site is fairly common. indoglobal.com provides an easy way to do this. You don't have to install your own HTML form to email CGI scripts. Of course you may still install your own CGI scripts if you wish.

Our preinstalled form to email handler resides on /global/nms-fmail.cgi. To make use of it, you need to write an HTML form that refers to that script. Here's an example HTML snippet code which will send mail to address feedback@example.com when someone submits the form.

<form method="POST" action="/global/nms-fmail.cgi">
  <input type="hidden" name="recipient"
    value="feedback@example.com" />
  <p>
    Please enter your comments<br />
    <input type="text" name="feedback" />
  </p>
  <p>
    <input type="submit" />
  </p>
</form>

Form Configuration

The hidden 'recipient' input field in the example above told the HTML form to email script who to send the email to. This is how the script configuration works. Here is the full list of field names that you can set using hidden form inputs.

  • recipient: the email address to which the form submission should be sent. If you would like it copied to more than one recipient then you can separate multiple email addresses with commas. Please note that you are not allowed to send emails to outside of your domain, for example you cannot set recipient field to email addresses not ending with example.com, assuming your domain account is example.com.

  • subject: the subject line for the email.

  • redirect: if this value is present, it should be a URL and the user will be redirected there after successful form submission. If you don't specify a redirect URL, then instead of redirecting, it will generate a success page telling the user that their submission was successful.

  • bgcolor: the background color of the success page.

  • background: the URL of the background image for the success page.

  • text_color: the text color for the success page.

  • link_color: the link color for the success page.

  • vlink_color: the vlink color for the success page.

  • alink_color: the alink color for the success page.

  • title: the title for the success page.

  • return_link_url: the target URL for a link at the end of the success page. This is normally used to provide a link from the success page back to your main page.

  • return_link_title: the label for the return link.

  • sort: This sets the order in which the submitted form inputs will appear in the email and on the success page. It can be the string 'alphabetic' for alphabetic order, or the string 'order:' followed by comma separated list of the input names. For example the sort field of 'order:name,email,age,comments' will have the fields ordered as such.

  • required: this is the list of fields that the user must fill in before they submit the form. If they leave any of these fields blank then they will be sent back to the form to try again.

  • missing_fields_redirect: if this is is set, it must be a URL, and the user will be redirected there if any of the fields listed in 'required' are left blank. Use this if you want finer control over the error that the user sees if they miss out a field.

  • env_report: This is a list of the CGI environment variables that should be included in the email. This is useful for recording things like the IP address of the user in the email. For example you could specify env_report value of 'HTTP_USER_AGENT,REMOTE_ADDR,REMOTE_HOST' if you want the form to report back to you the web browser, IP address, and hostname of the submitter.

  • print_blank_fields: if this is set then fields that the user left blank will be included in the email. Normally, blank fields are supressed to save space.

As well as the above hidden inputs, there are a couple of non hidden inputs which get special treatment.

  • email: this will be used as the address part of the sender's email address in the email.

  • realname: this will be used as the name part of the sender email address in the email.

Copyright © 2003 indoglobal.com

. .