1

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>
Fish Below the Ice
  • 1,273
  • 13
  • 23
Denoteone
  • 4,043
  • 21
  • 96
  • 150

1 Answers1

5

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

duncan
  • 31,401
  • 13
  • 78
  • 99
  • So could I wrap the whole thing in ? see my edits to my question above. Thanks for the help. +1 – Denoteone May 19 '15 at 08:08
  • you don't even need that ``... the `` tag acts like ``. If you wanted to send multiple emails based on the results of a query, you'd do ``, but as it looks like your query only returns 1 row, you don't need to do that either. – duncan May 19 '15 at 08:11
  • 1
    You never need it. The cfoutput tag in this answer could just as easily be a cfloop tag. Inside a mail block, they do the same thing. – Dan Bracuk May 19 '15 at 11:11