home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


  SERVER—By default, ColdFusion uses the server specified in the Mail section of the ColdFusion Administrator. You can override this choice of server by specifying a different mail server with the SERVER attribute.
  PORT—ColdFusion will automatically use the port set up in the ColdFusion Administrator (which is almost always port 25). Should you need to direct a mail message to a different port, you can specify the port number with the PORT attribute of the <CFMAIL> tag.
  TIMEOUT—If specified, the TIMEOUT attribute will override the timeout set up in the ColdFusion Administrator.

The capability to dynamically generate and send email messages enables you to add many useful features to your ColdFusion applications. You could do the following, for example, on an electronic commerce site:

  Send email to customers who make purchases from your site, confirming their order and thanking them for shopping with you. This can be sent right away so that customers feel that they are getting an immediate response from you.
  Send status messages to customers as their orders are filled. This enables you to inform them when their orders are shipped, if an item has to be back-ordered, and when they can expect to receive their orders.
  Send follow-up messages to assess satisfaction and to notify customers about upcoming specials.

Indeed, you could create and maintain an entire mailing list using ColdFusion. Subscribers could add themselves to the database and post messages to the list through HTML forms. Then, when it’s time to send a message to the list, you would query the list of recipients to get everyone’s email address:

<CFQUERY DATASOURCE=“mailinglist” NAME=“GetAddresses”>
SELECT name, emailaddress
FROM Subscribers
</CFQUERY>

Then you can use <CFMAIL> with the QUERY attribute to send a submitted message to each member of the list:

<CFMAIL QUERY=“GetAddresses” TO=“#name#” FROM=“Mailing List Admin”
  SUBJECT=“#Form.subject#”>
#Form.message#
</CFMAIL>


How ColdFusion Handles the Message Text

The content you place between the <CFMAIL> and </CFMAIL> tags is what ColdFusion uses to generate the body of the email message. An important thing to keep in mind is that ColdFusion may insert blank lines into the message where it has parsed out any CFML tags it encounters. Consider the following code, for example:

<CFMAIL TO=“#email# FROM=“confirm@yourserver.com”
  SUBJECT=“Address Confirmation” QUERY=“GetAddressInfo”>
Your name and address are shown below.  If any of this information
is incorrect, please reply to this message with the correct information.

#GetAddressInfo.name#
#GetAddressInfo.address1#
<CFIF #GetAddressInfo.address2# IS NOT “”>#GetAddressInfo.address2#</CFIF>
#GetAddressInfo.city#, #GetAddressInfo.state# #GetAddressInfo.zip#
</CFMAIL>

Notice in the body of the message that a <CFIF> tag checks the value of #GetAddressInfo.address2# to see if it is not blank. If it isn’t, then ColdFusion will output its value. If it is, then ColdFusion will parse out the entire line and keep going. Unfortunately, this produces a blank line in the resulting email and the recipient sees something like

Your name and address are shown below. If any of this information
is incorrect, please reply to this message with the correct information.

John Doe
123 Main Street

New York, NY 10033

To avoid this problem, what you can do is to compose a string that contains the contents of the message, and then place the variable containing the string between the <CFMAIL> and </CFMAIL> tags. The trick to doing this is to account for breaks to a new line, but ColdFusion makes this fairly easy with the Chr function. In the following code, the concatenation of Chr(13) and Chr(10) produces the carriage returns in the message. The ampersand (&) operator concatenates the strings.

<CFSET message = #GetAddressInfo.name# & Chr(13) & Chr(10)>
<CFSET message = message & #GetAddressInfo.address1# & Chr(13) & Chr(10)>
<CFIF #GetAddressInfo.address1# IS NOT “”>
 <CFSET message = message & #GetAddressInfo.address2# & Chr(13) & Chr(10)>
</CFIF>
<CFSET message = message & #GetAddressInfo.city# & “, ” &
 #GetAddressInfo.state# & “ ” & #GetAddressInfo.zip#>

<CFMAIL TO=“#email# FROM=“confirm@yourserver.com”
  SUBJECT=“Address Confirmation” QUERY=“GetAddressInfo”>
Your name and address are shown below.  If any of this information
is incorrect, please reply to this message with the correct information.

#message#
</CFMAIL>

Other Useful CFML Tags

Fifty-one CFML tags are available, and to fully describe them all would require several chapters instead of just this one. The tags you have read about so far are the ones that form the core of most ColdFusion applications, but many others are deserving of mention. This section briefly surveys some of the other CFML tags that are popular with developers.

These tags include:

  <CFABORT>—If ColdFusion encounters the <CFABORT> tag, it stops processing the template at that point and sends whatever HTML it has generated to the server. <CFABORT> is useful when you’re doing error checking on form data:
<CFIF NOT(IsNumeric(‘Form.age’))>
   <H1>Invalid age</H1>
   Please use your browser’s Back button and enter a valid age on the form.
   <CFABORT>
</CFIF>
...


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.