• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Lesson 4. Using Forms with ColdFusion > Emailing Form Information

Emailing Form Information

Up until this point, you have just been setting up code to redisplay the information that users have input. But it's most likely you will want to receive the information through email. This allows you to see the comments or questions quickly and respond to them quickly as well. ColdFusion offers built-in support for email, so emailing the form information will be a simple proposition.

On the second line of the page in the formoutput.cfm template, add the following line of code: <cfmail

Notice that there is no ending bracket on this tag. This is intentional; you haven't finished adding attributes yet. The <cfmail> tag allows you to send email using any SMTP (Simple Mail Transfer Protocol) server.

Add the following code after the <cfmail> tag:

subject=”Web comment or Question”>

By using the To and From attributes, you have specified who the email is going to and who the email is from. The Subject attribute allows you to set the subject of the message. Notice that the From attribute is using the form.email variable so it will use the email address the user submitted in the form.


You will need to specify a valid SMTP server with the server attribute. This lets ColdFusion know what mail server to use to send the message. You could use your local ISP's SMTP server—that is, the ISP you use for Internet access. It might look like this: server="mail.isp.net". Contact your ISP to find out what they allow. If you are working with a hosting provider that allows <cfmail>, they should already have a mail server set up in the ColdFusion Administrator for their server and you won't have to specify the server attribute.

After the <cfmail> tag insert this code:

The following email was sent: 
Name: #form.name#
Email: #form.email#
Comments: #form.comments#
Join Mailings: #form.mailinglist#

You can add whatever type of message you want after the <cfmail> tag. The message is preformatted, which is the same as if you had put text within HTML <pre> tags. The message will appear exactly as you type it; if you had typed all the information above on one line, you would get one line of text in the email.

Add the closing </cfmail> tag to the end of your message.

This completes the <cfmail> tag. Now when the user submits the form, not only will he see what he submitted, but you will receive an email to boot.


There may be a time when you want to send an HTML-enabled email—that is, use HTML formatting in your message. In order to do this with <cfmail> you need to add the “type” attribute and specify HTML as the type. So by adding type="html" under the <cfmail> tag you can use HTML text between the <cfmail> tags rather than preformatted text.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint