Cfmail in cfscript Here's a convenient little function I use for some of my more processing oriented pages. I love building content in cfscript however I find it really annoying having to close my cfscript tags to mail content. In general I don't like closing cfscript tags for anything if at all possible.

view plain print about
1<cffunction name="sendMail" output="false">
2    <cfargument name="to" required="yes">
3    <cfargument name="from" required="yes">
4    <cfargument name="subject" required="yes">
5    <cfargument name="message" required="yes">
6    <cfargument name="cc" required="no" default="">
7    <cfargument name="bcc" required="no" default="">
8    <cfargument name="type" required="no" default="">
10    <!--- Mail content --->
11    <cfmail to=""
12        cc=""
13        bcc="#arguments.bcc#"
14        from="#arguments.from#"
15        subject="#arguments.subject#"
16        type="#arguments.type#">

18        #arguments.message#
19    </cfmail>

Although incredibly simple, this little function can save lots of time, allowing you to pass all the content as if it's a built-in function in coldfusion.

To call it you only need the use the code below, replacing the test content with your own, if you'd like to specify HTML type messages or CC someone, you can do that as well, though these arguments are optional:

view plain print about
2this.sendmail("","","This test message","This is a test message","","","text");