Skip to main content
May 30, 2012
Answered

Three emails sent with one record each

  • May 30, 2012
  • 2 replies
  • 766 views

Hi all there are three records that result from the query but instead of sending all three results in the email it sends three emails with one record each. I can't use cfoutput in the cfmail tag. What do I do? Thanks 

<cfquery name="qNames" datasource="salesdb">
select * from company, industries, division
where Date(company.meeting) = '#DateFormat(Now(),"yyyy-mm-dd")#'
and company.SECTORS1 = industries.SECTORSIDS
and division.DEPARTMENTIDS = company.DEPARTMENT1
ORDER BY company</cfquery>

<cfmail to="barney@bedrock.com"
from=barney@bedrock.com
subject="Today's email"
type="text"
query="qNames">
Dear Fred

#company#
#sectorsnom#

</cfmail>

    This topic has been closed for replies.
    Correct answer Dan_Bracuk

    Use cfloop.

    2 replies

    Sreeindia
    Participating Frequently
    May 30, 2012

    Hi

    Just add Cfoutput to output the value of the query in Cfmail tags Like shown below.

    <cfquery name="qNames" datasource="salesdb">
    select * from company, industries, division
    where Date(company.meeting) = '#DateFormat(Now(),"yyyy-mm-dd")#'
    and company.SECTORS1 = industries.SECTORSIDS
    and division.DEPARTMENTIDS = company.DEPARTMENT1
    ORDER BY company</cfquery>

    <cfmail to="barney@bedrock.com"
    from=barney@bedrock.com
    subject="Today's email"
    type="text"
    query="qNames">
    Dear Fred

    <cfoutput>

    #company#
    #sectorsnom#

    </cfoutput>

    </cfmail>

    You can also use cfloop before the cftag and get the data stored using <cfsavecontent >. Inside Cfmail you can output cfsavecontent value

    Please let me know if this post could help

    Regards

    Sreekar

    May 30, 2012

    Hi Sreekar thanks for the help I used Dan's solution:

    <cfmail to=""
    from=""
    subject=""
    type="html">

    <cfloop  query = "qNames">
    <strong>#qNames.departmentnom#<br>
    #qNames.phone#<br>
    </cfloop>
    </cfmail>

    Dan_BracukCorrect answer
    Inspiring
    May 30, 2012

    Use cfloop.