I am not 100% on when to use cfoutput and how cfoutput can be used in the following example. Should the whole cfmail be wrapped in a cfoutput?
Background: I have a function that sends an email based on an if statement. The message of the email has variables that come from a cfquery.
<cffunction name="emailUpdate" access="public" returntype="string">
<cfargument name="usr_email" required="yes">
<cfargument name="status_update" required="yes">
<cfargument name="form_id" required="yes">
<cfquery name="emailformData" datasource="RC">
SELECT *
FROM Basic_Info
WHERE ID = <cfqueryparam value="#ARGUMENTS.form_id#">
</cfquery>
<cfoutput query="emailformData">
<cfmail
from="forms@email.us"
to="#usr_email#"
subject="Status Update">
<cfif status_update EQ 'Submitted'>
Form Submitted: The following quote request ID: #emailformData.ID# has been submitted on
#emailformData.Submission_Date# for the following party #emailformData.Sold_to_Party#. You will receive automated
updates via email when your submission changes status. <b>- Admin Team</b>
<cfelseif status_update EQ 'Assigned'>
Form Assigned by Admin Request ID: #emailformData.ID# for the following party #emailformData.Sold_to_Party# was
assigned to Admin ID #emailformData.Admin_ID# on #DateFormat(Now())#, #TimeFormat(Now())#.
Below is their direct contact information for any change requests or status updates. <b>- Admin Team</b>
<cfelseif status_update EQ 'Returned'>
Returned by Admin Form ID: #emailformData.ID# for the following party #emailformData.Sold_to_Party# was
returned by Admin ID #emailformData.Admin_ID# on #DateFormat(Now())#, #TimeFormat(Now())#
for the following reasons. Admin Notes: #emailformData.Admin_Notes#.
<b>- Admin Team</b>
<cfelseif status_update EQ 'Completed'>
Form Completed Form ID: #emailformData.ID# for the following party #emailformData.Sold_to_Party# has been
marked as COMPLETED on #DateFormat(Now())#, #TimeFormat(Now())#. The following Quote Number has been
assigned to this form #emailformData.Quote_Num#. The quote will be emailed to you. If the Admin added any closing notes to the form they will appear below:
#emailformData.Admin_Notes#
<b>- RFQ Admin Team</b>
</cfif>
</cfmail>
</cfoutput>
</cffunction>
You don't need it, unless perhaps you're doing looped output of a cfquery. e.g. if your emailformData query returned multiple rows (and it obviously doesn't), you might do:
<cfmail ...>
Here's the email data #form.name# asked for:
<cfoutput query="emailformData">
#emailformData.Sold_to_Party#
</cfoutput>
Sent on #dateFormat(now())#
</cfmail>
See Sample uses of the cfmail tag on the Adobe site, and this discussion on Ray Camden's site