Using CGIEmail - Example 2

 

This tutorial will teach you how to use the CGIEmail script that is pre-installed with your hosting account.

What is CGIEmail?
CGIEmail is a form mailing script, similar in function to Matt Wright's formmail.pl, but it uses a text based email template instead of just sending an email with a list of form variables.

Where is CGIEmail located?
http://www.yourdomain.com/cgi-sys/cgiemail

--------------------------------------------------------------------------------
This tutorial is broken down to 5 steps:
1.) Creating the HTML Form
2.) Creating the Email Template
3.) Testing your form.
4.) Extra features

1.) Creating the HTML Form

Create a simple html form in your favourite html editor. Something similar to this one:

First Name:
Last Name
Email:

HTML Source:

<FORM action="/cgi-sys/cgiemail/myform.txt" METHOD="post">
First Name: <INPUT name="firstname" type="text"><br>
Last Name: <INPUT name="lastname" type="text"><br>
Email: <INPUT name="emailaddress" type="text"><br>
<INPUT type="button" name="Button" value="Submit">
</FORM>

Save the html form. For this tutorial, we will save it as form.html.

Notice we chose the name of the email template to be myform.txt. You can name it whatever you wish (note: do not name it email.txt! it won't work). The path of the form action="" should be /cgi-sys/cgiemail plus the path to your email template file. In this case, our email template file, myform.txt, is located in the same place as our html form. But if it were located in say a subfolder named foobar, then the form action="" would look like this:

<FORM action="/cgi-sys/cgiemail/foobar/myform.txt" METHOD="post">

2.) Creating the Email Template

The Email template is just a regular plan text file. You can name it pretty much whatever you want, except "email.txt" . The first couple of lines must include the following information:

From:
To:
Subject:

To use the data submitted in the form, place the form field name inside []. We will name our template myform.txt for the purpose of this tutorial. So our email template will look like this:

From: [emailaddress]
To: you@yourdomain.com
Subject: Website Form data

Hi, my name is [firstname] [lastname]
My email address is [emailaddress]

Now save the myform.txt and form.html.

3.) Testing our Form

Now that we have our html page, and our email template, we just need to upload it to our website and test it. When you submit a form, you should see a page that shows the email that will be sent to the recipient.

4.) Extra CGIEmail Features

Here are some extra features that cgiemail supports:

Required Form Fields
Prepend required- to the name of the form field in both your html form, and the email template and it will force the user to enter a value for that field. Your code should look something like this:

form.html

<INPUT TYPE="text" NAME="required-firstname">

myform.txt

Hi, my name is [required-firstname]

Submission Success Page
You can have the user directed to a html page of your choice after they submit the form, instead of being taken to a page showing the email. To do this, put the following code in your html form page.

<INPUT TYPE="hidden" NAME="success" VALUE="http://www.domain.com/somepage.html">

  • 34 أعضاء وجدوا هذه المقالة مفيدة
هل كانت المقالة مفيدة ؟

مقالات مشابهة

How to add a form to your site using CGIEMAIL

How to add a form to your website, a quick and easy way to setup a contact or feedback form....