4 Replies Latest reply on May 1, 2014 10:38 AM by BKBK

    Send email with HTML output?

    no_name_123

      I have A CFM FILE(testing3.cfm):

       

      <cfset month = #URL.Month#>
      <cfset year = #URL.Year#>
      <CFQUERY>
      SELECT .....code..
      </CFQUERY>
      <HTML>
      
      
      <table>
      <thead>
      <tr >
      <th>Month</th>
      <th>Employee First Name</th>
      <th>Employee Last Name</th>
      <th>Stars<br/></th>
      
      
      <cfoutput query="">
      
      <tr >
      <TD></TD>
      </tr>
      
      </cfoutput>
      </table>
      
      
      --- more code, pretty much the same
      </HTML>
      

      I can see this 'report' when i click on the link depending on the year or month.(testing2.cfm) file

      report.PNG

       

      This file gets data from a table from every month,

      which works good.

      I want to be able to send a email of these results to who ever I choose to send it to.

      For example not the same people everytime , I would choose who I put in the 'TO' email part.

      So maybe there would be a button/link that would open up the email message (outlook) and i

      be able to see what is on  the html and be able to send it to the people I would like.

      Doing my research I have seen I can use 'cfemail' but this doesnt seem like it would be able

      to do what I want, only be able to do attachments.I would like to see the report i will send

      before I send it out( from the above code i can click on it).

      I be thinking maybe I can add a button/link next the the month in 'testing2.cfm', but im not sure if

      that would be the best way to do it.

      What would be the best way I can approch this? Any tips or articles I can read would help.

        • 1. Re: Send email with HTML output?
          WolfShade Level 4

          Everything between your HTML tags can go inside a <cfmail> tag.  You can do the CFSET stuff prior to the CFMAIL tag.

           

          BTW.. unless a variable is being used within a string, you don't need hashes.

           

          <cfset month = #URL.Month#> should be <cfset month = URL.Month>

           

          HTH,

           

          ^_^

          • 2. Re: Send email with HTML output?
            no_name_123 Level 1

            If i do it that way wouldnt that send it a email everytime i click on the link?

            • 3. Re: Send email with HTML output?
              WolfShade Level 4

              Precisely.  If you want to view the data before sending the email, create a second page that uses the CFMAIL tag and put a link to it on the first.

               

              ^_^

              • 4. Re: Send email with HTML output?
                BKBK Adobe Community Professional & MVP

                You could design it such as to be able to view the content and send the mail on the same page. An example follows.

                 

                testing2.cfm

                1/2014 (a link that takes you to testing3.cfm)

                 

                testing3.cfm

                <cfsavecontent variable="pageContent">

                <cfquery>

                </cfquery>

                <html>

                <body>

                <table>

                <thead>

                <tr >

                <th>Month</th>

                <th>Employee First Name</th>

                <th>Employee Last Name</th>

                <th>Stars<br/></th>

                etc.

                </body>

                </html>

                </cfsavecontent>

                 

                <p>

                <!--- Display page content --->

                <cfoutput>#pageContent#</cfoutput>

                </p>

                 

                <p>

                <!--- Clicking on this link will re-open the current page, and send mail --->

                <a href="testing3.cfm?action=mail">Send mail</a>

                </p>

                 

                <cfif isdefined("URL.action") and URL.action is "mail">

                    <cfquery name="getEmailAddresses" datasource="myDSN">

                        SELECT email FROM myTable

                    </cfquery>

                 

                    <cfmail query="getEmailAddresses"

                        from="admin@myCompany.com"

                        to="#getEmailAddresses.email#"

                        subject="Information">

                 

                Dear colleague,

                 

                Here is the information for January 2014.

                 

                    <cfoutput>#pageContent#</cfoutput>

                 

                Regards,

                Admin    

                    </cfmail>

                <p>The e-mails have been sent!</p>

                </cfif>