This tutorial will demonstrate how to create a contact us page and then have ColdFusion automatically email you the results of the form.

Ok, let's check to see if someone already filled the form out, if they did a hidden field called "Process" will have a value of one and the form will begin to process.

<CFIF IsDefined("process")>
     If the process field has a value of One, then do the following:
    <!--- Send the message to yourself, when the user posts it on your site. --->
<CFMAIL to="" from="#ContactEmail#" Subject="Contact From YourSite.Com">

        Message By: #ContactName# - #ContactEmail#
<!--- Send one to the person writing, thanking them and reminding them what they wrote. --->
<CFMAIL to="#ContactEmail#" from="From Email" Subject="The Subject!">

    Thank you for your message,
       We'll be in touch as soon as we can, we receive hundred and thousands
    of emails a day; so we might take a while, but we'll reply!

    Thanks again for visiting our site,
    Yourname - Webmaster

    You wrote:

    Message By: #ContactName# - #ContactEmail#

    Thanks for your message!

    <!--- If "Process" is not defined, let's show the form: --->

    <cfform action="contact.cfm" method="post">
    <input type="hidden" name="Process" Value="1">
    <table align="center" border="0" width="100%">
            <td width="40%" valign="top" align="right">Name:</td>
            <td width="60%"><cfinput type="text" name="ContactName" size="20" required="yes" message="Please Enter Your Name!"></td>
            <td width=
"40%" valign="top" align="right">Email:</td>
            <td width=
"60%"><cfinput type="text" name="ContactEmail" size="20" required="yes" message="Please Enter Your Email Address!"></td>
            <td width=
"40%" valign="top" align="right">Message:</td>
            <td width=
"60%"><textarea rows="4" name="ContactMessage" cols="20"></textarea></td>
            <td width=
"40%" valign="top" align="right"></td>
            <td width=
"60%"><input type="submit" value="Submit Contact Form"></td>



There you go, that's the contact page for ColdFusion.  Simple huh?

About This Tutorial
Author: Pablo Varando
Skill Level: Beginner 
Platforms Tested: CF5
Total Views: 153,170
Submission Date: August 13, 2002
Last Update Date: June 05, 2009
All Tutorials By This Autor: 47
Discuss This Tutorial
  • It does not work

  • Go here and read Kelan's comment at the very bottom. Wrap your contact page with this to mke sure critical info (passwords/emails) isn't displayed on errors. ************Kelan's comment************ A better method is... use This is what I do: ... ... ... The following errors were encountered on #dateformat(now(),"MM/DD/YYYY")# at #timeformat(now(),"HH:MM tt")# The above will trap any any errors in the clause, and e-mail them in the clause. The is a VERY COOL tool to use to debug any issues. Provides more information then the traditional debug tool cf throws on the screen.

  • I was wondering how I can get this contact information on the form to go into my sql database? Thanks!

  • I have never explored cfml like I have done in your site. It really inspired me to learn more and more. Thanks for the site.

  • Hey this is not working at all..

  • qs

  • Dear sirs , i have tried this form , but when i was running it , it gaves errors , i want to ask whether we should save all this form in a name " contact.cfm " i have tried it and is not working . thank you

  • sorry I'm new to CF, just want to know what's inside "contact.cfm". Thanks and best regards. rex


Sponsored By...
Mobile App Development (IOS, Android, Cordova, Phonegap, Objective-C, Java) - Austin, Texas Mobile Apps - Touch512, LLC.