An application page with the cfmail
tag dynamically generates e-mail messages based on the tag's settings. Some of the tasks you can accomplish with cfmail
include the following:
In the following example, the contents of a customer inquiry form submittal are forwarded to the marketing department. Note that the same application page could also insert the customer inquiry into the database.
< cfmail
from="#Form.EMailAddress#" to="marketing@MyCompany.com" subject="Customer Inquiry"> A customer inquiry was posted to our Web site: Name: #Form.FirstName# #Form.LastName# Subject: #Form.Subject# #Form.InquiryText# </cfmail>
In the following example, a query (ProductRequests) is run to retrieve a list of the customers who have inquired about a product over the last seven days. This list is then sent, with an appropriate header and footer, to the marketing department:
< cfmail
query="ProductRequests" from="webmaster@MyCompany.com" to="marketing@MyCompany.com" subject="Widget status report"> Here is a list of people who have inquired about MyCompany Widgets over the last seven days: <cfoutput> #ProductRequests.FirstName# #ProductRequests.LastName# (#ProductRequests.Company#) - #ProductRequests.EMailAddress#&##013; </cfoutput> Regards, The WebMaster webmaster@MyCompany.com </cfmail>
Note the use of the cfoutput
tag to present a dynamic list embedded within a normal cfmail
message. The text within the cfoutput
is repeated for each row in the ProductRequests query, while the text above and below it serve as the header and footer, respectively, for the mail message. The &##013; in the cfoutput block forces a carriage return between output records.
In the following example, a query (BetaTesters) retrieves a list of people who are beta testing ColdFusion. This query is then used to send a notification to each of these testers that a new version of the beta release is available:
<cfmail query="BetaTesters"
from="beta@MyCompany.com" to="#TesterEMail#" subject="Widget Beta Four Available"> To all Widget beta testers: Widget Beta Four is now available for downloading from the MyCompany site. The URL for the download is: http://beta.mycompany.com Regards, Widget Technical Support beta@MyCompany.com </cfmail>
Note that in this example, the contents of the cfmail
tag body are not dynamic, that is, the tag does not use any # delimited dynamic parameters. What is dynamic is the list of e-mail addresses to which the message is sent. Note the use of the TesterEMail column from the BetaTesters query in the to
attribute.