If you have access to a coldfusion server then you you have the ability to handle form processing in a couple lines of code.
With other methods you would make the “action” of your form post to a script held in a cgi directory. You would have to find that script and edit it to allow content from your form and to process the mail to an allowed address.
Such an example would be “FormMail” to use the FormMail script you have to edit the “.FormMail.conf” file. It looks a little like this:
<code>
#### NMS Secure FormMail v2.20 2002/11/21 (Release 1.0)
####
#### *Configuration File*
#### If any values are not set properly, FormMail WILL NOT work.
####
#### Save this file in your home directory (/home/username/) named ‘.FormMail.conf’
####
# Set this to ‘1’ if you recieve any errors. They will
# Be displayed to the browser in a more verbose manner.
[DEBUGGING]
0
[/DEBUGGING]
# This address will recieve bounced messages if any of the emails
# cannot be delivered, and should be set to your e-mail address.
#
[postmaster]
you@yourdomain.com
[/postmaster]
# A list of the email addresses that formmail can send
# email to. The elements of this list can be either
# simple email addresses (like ‘you@your.domain’) or
# domain names (like ‘your.domain’). If it’s a domain
# name then *any* address at the domain will be allowed.
#
# Also see NOTE below for aliases.
#
# NOTE: One address/domain per line
#
[allow_mail_to]
yourdomain.com
you@yahoo.com
[/allow_mail_to]
# A hash for predefining a list of recipients in the
# script, and then choosing between them using the
# recipient form field, while keeping all the email
# addresses out of the HTML so that they don’t get
# collected by address harvesters and sent junk email.
#
# For example, suppose you have three forms on your
# site, and you want each to submit to a different email
# address and you want to keep the addresses hidden.
#
# In the HTML form that should submit to the recipient
# ‘me@mydomain.com’, you would then set the recipient
# with:
#
# <input type=”hidden” name=”recipient” value=”me” />
#
# NOTE: If an alias is set for any e-mail address, then it is
# not required to be in the [allow_mail_to] block, it
# is automatically allowed.
#
# NOTE: One alias per line.
#
[recipient_alias]
me=>you@yourdomain.com
him=>you@yaoo.com,you@hotmail.com
[/recipient_alias]
# If this flag is set to 1 then an additional email
# will be sent to the person who submitted the
# form.
#
# CAUTION: with this feature turned on it’s
# possible for someone to put someone else’s email
# address in the form and submit it 5000 times,
# causing this script to send a flood of email to a
# third party. This third party is likely to blame
# you for the email flood attack.
#
[send_confirmation_mail]
0
[/send_confirmation_mail]
# The header and body of the confirmation email
# sent to the person who submits the form, if the
# [send_confirmation_mail] flag is set. In the
# example below, everything between the lines:
#
# [confirmation_text]
# and
# [/confirmation_text]
#
# is treated as part of the email.
# !!IMPORTANT!!
# Everything before the first blank line is taken as part of
# the email header, and everything after the first
# blank line is the body of the email.
[confirmation_text]
From: you@yourdomain.com
Subject: Your Form Submission
Thank you for your submission.
[/confirmation_text]
# The Cascading Style Sheet (CSS) used for the ‘thank you’ page
# if a redirect is not used. This is an absolute URL.
#
# i.e. /css/site.css would be http://yourdomain.com/css/site.css
#
# This may be left blank.
#
[style]
/css/site.css
[/style]
# The Character set used for parsing form data and for the resulting
# ‘Thank You’ page after form submission.
#
# This may be left blank.
#
[charset]
iso-8859-1
[/charset]
</code>
See, You have to change this.. not that… add your list of e-mail addresses here.. etc.
With ColdFusion, you can handle all this with just a few additional lines when you are building your form.
Since we are going to handle this form all in one page we need to set some conditions as we don’t want the form trying to process <em>every</em> time the page is loaded.
To handle this we will start our form like so:
<code>
<cfif not isdefined(“form.message”)>
<p>Please use the form below to contact us!</p>
<cfform name=”contactform” action=”contact.cfm” method=”post”>
<table>
<tr>
<td>Name:</td>
<td><cfinput name=”name” id=”name” type=”text” required=”Yes” message=”Please Enter your name”></td>
</tr>
<tr>
<td>Email Address:</td>
<td><cfinput name=”email” id=”email” required=”Yes” type=”text” message=”Please provide a valid email address”></td>
</tr>
<tr>
<td>Subject:</td>
<td><cfinput name=”subject” id=”subject” type=”text” required=”Yes” message=”Please tell us what you want”></td>
</tr>
<tr>
<td>Message:</td>
<td><textarea name=”message” rows=”5″ cols=”50″></textarea></td>
</tr>
<tr>
<td colspan=”2″><input name=”submit” id=”submit” value=”Send Message!” type=”submit”></td>
</tr>
</table>
</cfform>
</code>
<cfelse>
</cfif>
</code>
Ok.. here we are saying.. hey, if form.message is empty, lets show that form … notice the “cfelse” before the closing “/cfif”… that tells the form ok.. if there <em>IS</em> something there, then do this.. and it will do what you put after the “cfelse”.
In our case we want to process the form so we would do something like:
<code>
<cfelse>
<cftry>
<cfmail from=”#trim(form.email)#” to=”you@you.com” replyto=”#trim(form.email)#” subject=”You.com Contact Form: #form.subject#”>
Name: #form.name#
Email: #form.email#
Subject: #form.subject#
Date: #dateformat(now(),”ddd, mmmm dd, yyyy”)#
Time: #timeformat(now(),”h:mm:sstt”)#
Message:
#form.message#
</cfmail>
<cfcatch></cfcatch>
</cftry>
<h1>Thanks #form.name#!</h1>
<br>
<p><strong>We will get back to you ASAP!!</strong></p>
</cfif>
</code>
We set some fields in the form as “required” so, granted everything contains data this section will populate a “cfmail” tag with the contents of our form.
After the form processes we Thank the user by name for contacting us and tell them that the form is processed.
This is a simple, effective way to process your form to e-mail. And, it’s very easy to change when it’s time to update.
© 2006 – 2009, Robert Owen. All rights reserved.