• Horn Player – Computer Dude – Gig Pig …
  • Home
  • About
  • Blog
  • Services
  • Contact
  • Webmail
  • Terms

Robert A. Owen - Musician - Technology Leader

Music, Technology, Rants and Funnies - Randomness at its best!

  • Blog
  • Internet
    • IIS 6
    • IIS 7.5
    • Javascript
    • Web Design
      • WordPress
      • Coldfusion
  • Support
    • MicroSoft
      • Powershell
      • Surface
      • Windows10
      • Zune
    • PC-Care
    • Software
    • Virus
      • Email Scam
    • Vista Quest
    • Windows 7
  • Pictures
    • Instagram
  • Music
  • Friday Funnies
  • General
    • CoWorking
    • Gadgets
    • Politico
    • Random – TidBit
    • Rant
    • Review
    • Site of the Week
    • Useless
    • Xbox
      • Games
You are here: Home / Coldfusion / Simple Contact Form

Simple Contact Form

November 9, 2006 By Robert Owen

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.

Related Posts Plugin for WordPress, Blogger...

Filed Under: Coldfusion Tagged With: Address Domain, Address Harvesters, Address Postmaster, Cgi Directory, Coldfusion Server, Configuration File, Couple Lines, Domain Name, Domain Names, E Mail Address, Elements, Email Address, Email Addresses, Form Processing, Formmail Script, Hash, Home Directory, Junk Email, Lt, Release 1

Robert Owen A Horn Player turned salesman, turned Computer Consultant & Horn Player, Turn Network Engineer & Horn Player.... Well, How about a Horn player who does a lot of other stuff? More about me. FacebookInstagramLinkedInTwitter

To Stay up-to-date on all of my crazy Ramblings, enter your e-mail address below.

You'll be amazed!

Recent Posts…

  • Instagram Photos
  • Time for more Pictures
  • Windows 10 – Forget Wireless Network
  • Powershell to check and start a service
  • Its Amazing – Shia LaBeouf

Recent Comments

  • David Gray on Create a Shortcut to open in your Alternate BrowserTwelve years on, this tip remains useful. Though I…
  • Sue K on Use the Snipping Tool to Capture MenusThanks you so much! I could never figure out how t…
  • aa on Increase IIS File Upload LimitsSuperb Robert..after wasting 2 days..this is perfe…
  • León on Windows 7 error 86Funciono para Windows 7 , también descubrí que la…
  • Nicole Larkin on Use the Snipping Tool to Capture MenusNine years later and your post is still helpful. T…

[footer_backtotop]

Content Copyright © 2023 OWEN CONSULTING · All Rights Reserved · Log in