CFMAIL with loop and attachment

coldfusion cfmail

106 观看


21 作者的声誉

I have a query that gets data for a sales report for a group of stores.

I need to create a PDF of the monthly sales for each store and then email the sales manager the report for his/her store only.

The create PDF part is working fine. It creates a separate report for each store.

When I try to email the report, it sends one report for each record instead of one report for all sales people. EX: If there are 4 people on the report for store #1, the sales manager will get 4 reports instead on 1 report.

Here is my code: Creating the PDF

     <cfoutput query="data" group="site_name">
     <cfdocument format="pdf" overwrite="yes" fontembed="yes" 
     filename="xxxxxxxxxxxxxxxsite_name#.pdf" margintop="0.25" 
     marginbottom="0.25" marginleft="0.25" marginright="0.25" 
     <table width="100%" align="center" border="1" cellpadding="5"
     <tr bgcolor="##e1e8f7">
     <td colspan="8" align="center">Sales Report  -#today#-#site_name#</td>
     <tr align="center">
     <td>Sales Person</td>
     <td>Total Sales</td>
    <td>#firstName# #lastName#</td>


    <cfmail query="data" to="#salesmanageremail#" subject="monthly sales 
    <style type="text/css">
    body { font-size: 12px; font-family: Arial; }
    Report attached.
   <cfmailparam file="xxxxxxxxxxxxxxxsite_name#.pdf">

How do I email one report per store containing all of the data to each sales manager?

作者: Monique Boea 的来源 发布者: 2017 年 12 月 27 日

回应 (1)


18763 作者的声誉


You can treat your cfmail tag as a cfoutput tag. That includes using the group attribute as you did when creating the pdf.

Alternatively, you can put the cfmail tag within the cfoutput block you are using to create the pdf. All things considered, that's the approach I would take. That way you send the correct file for each site.

作者: Dan Bracuk 发布者: 27.12.2017 05:24