Difference between revisions of "CGI Email"

From XMission Wiki
Jump to: navigation, search
m (Creating the Template Message)
(Introduction)
Line 3: Line 3:
  
 
<div class="messagebox metadata">'''Note''':  These instructions assume you are familiar with basic HTML  and fill-out forms. You should also note that all file names and form  fields are case sensitive. XMission uses a CGI tool called cgi-email  to generate email from a fill-out form page without the need for  a separate email client (which would be needed with a <a href=mailto:acctname@xmission.com> tag). To configure your own email form, you need to create a form  with the appropriate "action" URL and create a template email message.  These steps are outlined in detail below.</div>   
 
<div class="messagebox metadata">'''Note''':  These instructions assume you are familiar with basic HTML  and fill-out forms. You should also note that all file names and form  fields are case sensitive. XMission uses a CGI tool called cgi-email  to generate email from a fill-out form page without the need for  a separate email client (which would be needed with a <a href=mailto:acctname@xmission.com> tag). To configure your own email form, you need to create a form  with the appropriate "action" URL and create a template email message.  These steps are outlined in detail below.</div>   
 
For easy reference and comparison, XMission creates a simple email  form in your public_html directory when your account is activated.  The files are mail.html (the fill-out form)  and mail.txt (the template message). You may  choose to modify these to fit your needs or just view their structures  to better understand how you will need to create your own. 
 
  
 
For more details about CGI Email, or to learn how to set it up on  your own server, refer to [http://web.mit.edu/wwwdev/cgiemail/ MIT's CGI Email] help pages.
 
For more details about CGI Email, or to learn how to set it up on  your own server, refer to [http://web.mit.edu/wwwdev/cgiemail/ MIT's CGI Email] help pages.

Revision as of 14:47, 1 October 2009

Archives.png

Introduction

For more details about CGI Email, or to learn how to set it up on your own server, refer to MIT's CGI Email help pages.

Creating the Form

When you create your form, there are two main things you will need to do. The first is to be certain that all the form fields have a unique name. The second is to properly set the <form> tag. Any standard form entries may be used (such as radio buttons, check boxes, pull-down select menus, etc.). Below is a short example of a proper form, but you may also review your mail.html.

<html>
<head>
<title>John Doe's Email Form</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Please fill out the form below.</p>
<hr>
<form method="POST" action="http://www.xmission.com/cgi-bin/cgiemail/~username/mail.txt">
Your Name: <input type="text" name="name" size="50"><br>
E-Mail Address: <input type="text"  name="required-email" size="50"><br>
Subject: <input type="text" name="subject"  size="50"><Br>
<Br>
Message / Request: <Br>
<textarea name="content" rows=10 cols=66></textarea>
<Br> 
<input type="submit" value="Send" name="submit">
<input type="reset" value="Clear" name="reset">
</form>
</body>
</html>  


In red, you will see the <form> tag. The method will be post, and the action will be your template message through our cgi-email script. The syntax shown in the form tag above should be followed exactly. You will, of course, replace "acctname" with your XMission account name, and mail.txt with the location and name of your template message. Your template message must be located in your public_html directory or a sub-directory within it. To show an example of a variation, the XMission username will be "web", the template message will be located in the public_html/contact/ directory, and it will be named "order.txt".
<form method="POST"  action="http://www.xmission.com/cgi-bin/cgiemail/~web/contact/order.txt">

A notable bonus of using cgi-email is shown above in green. You can make a field required by preceding its name with "required-". XMission recommends that you make the email address a required field. The reason being, if you reply to your form and there is no email address present, your reply will automatically be sent to XMission's webmaster instead of the intended recipient.


Creating the Template Message

The template message is the email message that will be sent to you when the form is submitted. It's a simple text file in the format of an email message. Because cgi-email sends this text file as an email message, it must have the proper header fields to work properly and must not have any blank lines before the first field.

The format of the template after the header lines is up to you. The only thing you must have is the names of the form fields in brackets. Below is an example of a text template to go with the form above. You may also review your mail.txt file.

To: John Doe <username@xmission.com>
From: [name] <[required-email]>
Reply-to: [required-email]
Subject: [subject] 

Sender's Name: [name]
Email Address: [required-email] 

Comments or Request:
[content] 

You would, of course, replace "John Doe" with the name of the person or department that the email message is being sent to, and "username@xmission.com" with the destination email address.

Adding a "success" Page

By default, there is a text confirmation page that notifies the sender that the email message was sent successfully. However, some XMission subscribers would like to replace it with a nicer HTML success page. This is easy with cgi-email.

You will need to open the HTML form and add a hidden form field. The syntax will look like the following example

<input type="hidden" name="success" value="http://www.xmission.com/~acctname/successpage.html">

Unlike the other form fields, you cannot change the name of the "success" field. It must be named "success" for it to work properly. The value is the URL of the success page that you want to appear after the sender has successfully completed and submitted the form. The example above will show the file named "successpage.html" in acctname's public_html directory. The success page value must be a fully-qualified URL, so you may want to be sure it works in a browser first.