A Simple Contact Us Page….
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="webmaster@yoursite.com" from="#ContactEmail#" Subject="Contact From YourSite.Com">
       
#ContactMessage#

        Message By: #ContactName# - #ContactEmail#
        ========================================
    </CFMAIL>
   
<!--- 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
    Webmaster@Yoursite.Com

    You wrote:
    #ContactMessage#

    Message By: #ContactName# - #ContactEmail#
    ========================================
    </CFMAIL>

    Thanks for your message!

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

    <cfform action="contact.cfm" method="post">
    <input type="hidden" name="Process" Value="1">
    <table align="center" border="0" width="100%">
        <tr>
            <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>
        </tr>
        <tr>
            <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>
        </tr>
        <tr>
            <td width=
"40%" valign="top" align="right">Message:</td>
            <td width=
"60%"><textarea rows="4" name="ContactMessage" cols="20"></textarea></td>
        </tr>
        <tr>
            <td width=
"40%" valign="top" align="right"></td>
            <td width=
"60%"><input type="submit" value="Submit Contact Form"></td>
        </tr>
    </table>

    </cfform>

</CFIF>

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

All ColdFusion Tutorials By Author: Pablo Varando
Download the EasyCFM.COM Browser Toolbar!