Skip to main content
Known Participant
Apr 30, 2014 8:51 PM UTC
Question

Send email with HTML output?

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

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.

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

BKBK
Community Expert
Community Expert
May 1, 2014 5:37 PM UTC

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>

Translate
WolfShade
Legend
Apr 30, 2014 9:15 PM UTC

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,

^_^

Translate
Known Participant
Apr 30, 2014 9:17 PM UTC

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

Translate
WolfShade
Legend
May 1, 2014 12:43 PM UTC

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.

^_^

Translate