Link to home
Start Free TrialLog in
Avatar of g118481
g118481

asked on

Help with CFMAIL sending just one record from the query.

I am using CFMAIL to send a report automatically.  In my testing I have set up two records in the table that the mail query looks at to populate the body of the email.

Problem is that the email contains just one of the records.
How do I change my code to send an individual all the records associated to that person?

Here is my simple code:

<cfloop query="get_mail">
  <cfmail to="#email#" cc="#pmemail#" from="me@me.com" subject="Overdue Assessment" type="HTML">

<!--  body of the email here -->

</cfmail>
</cfloop>
ASKER CERTIFIED SOLUTION
Avatar of TallerMike
TallerMike

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Noodles22
Noodles22

<cfmail query="get_mail"to="#email#" cc="#pmemail#" from="me@me.com" subject="Overdue Assessment" type="HTML">
<!--  body of the email here -->
</cfmail>

Your cfloop code should work the same as above, but you might want to check that your query is returning more than one record

<cfdump var="#getmail#">
<cfloop query="get_mail">
 <cfmail to="#email#" cc="#pmemail#" from="me@me.com" subject="Overdue Assessment" type="HTML">

Dear #person#,

Here are your records associated with you:

<cfquery name="your_records">
select * from records
where person='#person#'
</cfquery>
#your_records.records#<br>

</cfmail>
</cfloop>
what u cdl also do is

<CFSET x = "">

<cfquery NAME="get_mail">
    select ......
</CFQUERY>

<cfloop query="get_mail">
    <CFSET x = "#table_FieldName#"><!--- u can use multiple text along with htmls for formatting as well - put everything in "x" for all the records the user has --->    
</CFLOOP>

then send him one mail with all records - instead of multiple emails of all records !

<cfif x NEQ "">
    <cfmail to="#email#" cc="#pmemail#" from="me@me.com" subject="Overdue Assessment" type="HTML">
    Dear #name_of_person#
   
        #x#
   
    thanx
    #admin_Name#
    </cfmail>
</CFIF>

let me know

K'Rgds
Anand