Server Time:
Monday May 12 2008 06:44 AM  
Your Time:
  
HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

Keep your CFML in a database, then CFMAIL it!
by: Derrick Anderson
Email this tutorial to a friend Display Printer Friendly Format
[Download in PDF Format] [Download in FlashPaper Format]

<!---
This example uses a table called EmailTemplates with the following columns
`ID` INT(11)
`sender` VARCHAR(255)
`subject` VARCHAR(255)
`htmlbody` BLOB //The html pages are stored in this column
`textbody` BLOB //The text pages are stored in this column
--->


<!--- Set defaults --->
<cfparam name="mailto" default="[Email Address]">
<cfparam name=
"mailID" default="59">
<cfparam name=
"path_to_file" default="C:\path_to_file\">
<cfparam name=
"DSN" default="MYDSN">

<!--- Create a random filename for the html doc--->
<cfset html_file = #RandRange(1000,100000)#&'.cfm'>

<!--- Create a random filename for the text doc--->
<cfset text_file = #RandRange(1000,100000)#&'.cfm'>

<!--- Query the database for the proper email to send, choose your own criteria --->
<cfquery datasource="#MYDSN#" name="getliterature">
    SELECT * FROM EmailTemplates WHERE ID = #mailID#
</cfquery>

<!--- Write the temporary file with the HTML contents of the email body --->
<cffile action="write" nameconflict="makeunique" file="#path_to_file##Variables.html_file#" output="#getliterature.htmlbody#">

<!--- Write the temporary file with the TEXT contents of the email body --->
<cffile action="write" nameconflict="makeunique" file="#path_to_file##Variables.text_file#" output="#getliterature.textbody#">

<!--- Save the variable with the contents of the saved HTML file --->
<cfsavecontent variable="HTMLBody">
    <cfoutput>
        <cfinclude template=
"#Variables.html_file#">
    </cfoutput>
</cfsavecontent>

<!--- Save the variable with the contents of the saved TEXT file --->
<cfsavecontent variable="TextBody">
    <cfoutput>
        <cfinclude template=
"#Variables.text_file#">
    </cfoutput>
</cfsavecontent>

<!--- Send the mail message--->
<cfmail to="#mailto#" from="#getliterature.sender#" subject="#getliterature.subject#" type="html">
    <cfmailpart type=
"html">
       
#HTMLBody#
    </cfmailpart>
    <cfmailpart type=
"text">
       
#TextBody#
    </cfmailpart>
</cfmail>


<!--- Delete the temporary file created earlier --->
<cffile action="delete" file="#path_to_file##Variables.html_file#">
<cffile action=
"delete" file="#path_to_file##Variables.text_file#">
 


Date added: Tue. March 30, 2004
Posted by: Derrick Anderson | Views: 8129 | Tested Platforms: CFMX | Difficulty: Intermediate
Categories Listed: Best Practices

HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

This author's other tutorials:
Boost your applications performance with cached CFCs
When using the cfinvoke tag or the CreateObject function on your pages, it adds CPU time to process the requests to load all of those objects into memory. Under load this can make quite a difference in your page response times. One way to get around it is to put those objects into a shared scope so they only get instantiated once. This will save memory and CPU time on your server. - Date added: Thu. August 31, 2006
Please rate this tutorial:
5 Stars 4 Stars 3 Stars 2 Stars 1 Stars
Comments on this tutorial
Read previous comments on this particular tutorial
BS
Nice to see things that I wrote are on the web now under somebody elses name with cfmail added to it ;)
Posted by: Annon
Posted on: 10/29/2005 06:29 AM
don't think so pal
If you are suggesting that i copied this from you, you are mistaken.

CF Code is not very complex, many people have written code just like the code tutorials here on easycfm, you should not assume you've been copied when you see similar code to what you may have written in the past, i see it all the time.
Posted by: DA
Posted on: 11/01/2005 08:02 AM
Thanks a bunch!
Thanks man, this is just what I needed. Not all of it, but a decent chunk I won't have to reinvent!
Posted by: PJ
Posted on: 08/18/2006 05:45 AM
Post a new comment on this tutorial
post a new comment on this particular tutorial
Your Name:
Your Email:
Comment Title:
Comments:
Key Phrase:
 
Skyscrapper Banner Advertisement
ProWorkFlow.Com

You are 1 of 700 active sessions! | Privacy | Company
Copyright © 2002 EasyCFM.Com, LLC. (Easy ColdFusion Tutorials) All Rights Reserved
All other trademarks and copyrights are the property of their respective holders.
ColdFusion Hosting ColdFusion Hosting
ADD TO:
Blink
Del.icio.us
Digg
Furl
Google
Simpy
Spurl
Y! MyWeb