Emailing Form Information

I l @ ve RuBoard

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.

  1. 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.

  2. Add the following code after the <cfmail> tag:

     to="schmidt@hungrycow.com"  from="#form.email#" 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.

    NOTE

    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 serverthat 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.

  3. 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.

  4. 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.

NOTE

There may be a time when you want to send an HTML-enabled emailthat 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.


I l @ ve RuBoard


Macromedia ColdFusion 5. Training from the Source
Macromedia ColdFusion 5 Training from the Source (With CD-ROM)
ISBN: 0201758474
EAN: 2147483647
Year: 2002
Pages: 99
Authors: Kevin Schmidt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net