CFMAIL with loop and attachment

coldfusion cfmail

106 观看

1回复

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" 
     pagetype="Letter"
     filename="xxxxxxxxxxxxxxxsite_name#.pdf" margintop="0.25" 
     marginbottom="0.25" marginleft="0.25" marginright="0.25" 
     backgroundvisible="yes">
     <table width="100%" align="center" border="1" cellpadding="5"
     cellspacing="0"> 
     <tr bgcolor="##e1e8f7">
     <td colspan="8" align="center">Sales Report  -#today#-#site_name#</td>
     </tr>
     <tr align="center">
     <td>Sales Person</td>
     <td>Total Sales</td>
     </tr>
     <cfoutput>
     <tr>
    <td>#firstName# #lastName#</td>
    <td>#totalSales#</td>
    </tr>
    </cfoutput>
    </table>
    </cfdocument>
    </cfoutput>

CFMAIL

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

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

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

回应 1


3

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 发布者: 2017 年 12 月 27 日
32x32