• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 529
  • Last Modified:

Embed HTML Table within E-mail body through CFMAIL

I would like to e-mail out a table that is embedded within the e-mail message and use CFMAIL to send it.  I can get the CFMAIL to send to the users, but I can't figure out how to embed the table of information into the body of the e-mail.  Here is the table I want to put in the e-mail body.


<TABLE border="1" bordercolor="black" style="TABLE {font-family:tahoma; font-size:10pt; }">
<FONT size=2>Click on Column Heading to sort</FONT>
<CFOUTPUT query="QUERY">
<TR>
      <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=name">Contact Name</A></B></TD>
      <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=Company">Company</A></B></TD>
      <TD width="150" align="left"><B><A href="page.cfm?username=#username#&orderby=email">E-Mail Address</A></B></TD>
      <TD width="100" align="left"><B><A href="page.cfm?username=#username#&orderby=phone">Phone Nbr</A></B></TD>
      <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=code">Product Code</A></B></TD>
      <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=type">Size</A></B></TD>
      <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=grade">Grade</A></B></TD>
      <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=variety">Variety</A></B></TD>
      <TD width="100" align="left"><B><A href="page.cfm?username=#username#&orderby=label">Label</A></B></TD>
      <TD width="50" align="left"><B><A href="page.cfm?username=#username#&orderby=qty">Qty</A></B></TD>
      <TD width="50" align="left"><B><A href="page.cfm?username=#username#&orderby=price">Price</A></B></TD>
      <TD width="20" align="left"><B>Edit</B></TD>
      <TD width="20" align="left"><B>Delete</B></TD>
      </TR>
</CFOUTPUT>
<CFOUTPUT QUERY="Query">
      <TR>
      <TD width="200" align="left">#Name#</TD>
      <TD width="200" align="left">#Company#</TD>
      <TD width="100" align="left"><A href="mailto:#email#">#email#</A></TD>
      <TD width="75" align="left">#phone#</TD>
      <TD width="200" align="left">#code#</TD>
      <TD width="200" align="left">#type#</TD>
      <TD width="200" align="left">#grade#</TD>
      <TD width="200" align="left">#variety#</TD>
      <TD width="100" align="left">#label#</TD>
      <TD width="50" align="left">#qty#</TD>
      <TD width="50" align="left">#price#</TD>
      <TD width="20" align="left"><A href="page.cfm?ID=#ID#&amp;username=#username#">Edit</A></TD>
      <TD width="20" align="left"><A href="page.cfm?ID=#ID#&amp;username=#username#">Delete</A></TD>
      </TR>
      </CFOUTPUT>
</TABLE>

can this be done and if so how?  Thanks in advance
0
austintre
Asked:
austintre
1 Solution
 
Tacobell777Commented:
<cfmail to="email here" from="email here" subject="subject here" type="html" >
<cfmailpart type="html">
<TABLE border="1" bordercolor="black" style="TABLE {font-family:tahoma; font-size:10pt; }">
<FONT size=2>Click on Column Heading to sort</FONT>
<CFOUTPUT query="QUERY">
<TR>
     <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=name">Contact Name</A></B></TD>
     <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=Company">Company</A></B></TD>
     <TD width="150" align="left"><B><A href="page.cfm?username=#username#&orderby=email">E-Mail Address</A></B></TD>
     <TD width="100" align="left"><B><A href="page.cfm?username=#username#&orderby=phone">Phone Nbr</A></B></TD>
     <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=code">Product Code</A></B></TD>
     <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=type">Size</A></B></TD>
     <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=grade">Grade</A></B></TD>
     <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=variety">Variety</A></B></TD>
     <TD width="100" align="left"><B><A href="page.cfm?username=#username#&orderby=label">Label</A></B></TD>
     <TD width="50" align="left"><B><A href="page.cfm?username=#username#&orderby=qty">Qty</A></B></TD>
     <TD width="50" align="left"><B><A href="page.cfm?username=#username#&orderby=price">Price</A></B></TD>
     <TD width="20" align="left"><B>Edit</B></TD>
     <TD width="20" align="left"><B>Delete</B></TD>
     </TR>
</CFOUTPUT>
<CFOUTPUT QUERY="Query">
     <TR>
     <TD width="200" align="left">#Name#</TD>
     <TD width="200" align="left">#Company#</TD>
     <TD width="100" align="left"><A href="mailto:#email#">#email#</A></TD>
     <TD width="75" align="left">#phone#</TD>
     <TD width="200" align="left">#code#</TD>
     <TD width="200" align="left">#type#</TD>
     <TD width="200" align="left">#grade#</TD>
     <TD width="200" align="left">#variety#</TD>
     <TD width="100" align="left">#label#</TD>
     <TD width="50" align="left">#qty#</TD>
     <TD width="50" align="left">#price#</TD>
     <TD width="20" align="left"><A href="page.cfm?ID=#ID#&amp;username=#username#">Edit</A></TD>
     <TD width="20" align="left"><A href="page.cfm?ID=#ID#&amp;username=#username#">Delete</A></TD>
     </TR>
     </CFOUTPUT>
</TABLE>
</cfmailpart>
<cfmailpart type="text">
text version here if you need it, otherwise delete this part
</cfmailpart>
</cfmail>
0
 
mrichmonCommented:
One change to tacobell'ss code :

Don't use cfoutput inside cfmail - instead use cfloop - more efficeint

ANd one comment on yours - why do you loop twice?  Shouldn't the header row only appear once?

 <cfmail to="email here" from="email here" subject="subject here" type="html" >
<cfmailpart type="html">
<TABLE border="1" bordercolor="black" style="TABLE {font-family:tahoma; font-size:10pt; }">
<FONT size=2>Click on Column Heading to sort</FONT>
<TR>
     <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=name">Contact Name</A></B></TD>
     <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=Company">Company</A></B></TD>
     <TD width="150" align="left"><B><A href="page.cfm?username=#username#&orderby=email">E-Mail Address</A></B></TD>
     <TD width="100" align="left"><B><A href="page.cfm?username=#username#&orderby=phone">Phone Nbr</A></B></TD>
     <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=code">Product Code</A></B></TD>
     <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=type">Size</A></B></TD>
     <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=grade">Grade</A></B></TD>
     <TD width="200" align="left"><B><A href="page.cfm?username=#username#&orderby=variety">Variety</A></B></TD>
     <TD width="100" align="left"><B><A href="page.cfm?username=#username#&orderby=label">Label</A></B></TD>
     <TD width="50" align="left"><B><A href="page.cfm?username=#username#&orderby=qty">Qty</A></B></TD>
     <TD width="50" align="left"><B><A href="page.cfm?username=#username#&orderby=price">Price</A></B></TD>
     <TD width="20" align="left"><B>Edit</B></TD>
     <TD width="20" align="left"><B>Delete</B></TD>
     </TR>
<CFLOOP QUERY="Query">
     <TR>
     <TD width="200" align="left">#Name#</TD>
     <TD width="200" align="left">#Company#</TD>
     <TD width="100" align="left"><A href="mailto:#email#">#email#</A></TD>
     <TD width="75" align="left">#phone#</TD>
     <TD width="200" align="left">#code#</TD>
     <TD width="200" align="left">#type#</TD>
     <TD width="200" align="left">#grade#</TD>
     <TD width="200" align="left">#variety#</TD>
     <TD width="100" align="left">#label#</TD>
     <TD width="50" align="left">#qty#</TD>
     <TD width="50" align="left">#price#</TD>
     <TD width="20" align="left"><A href="page.cfm?ID=#ID#&amp;username=#username#">Edit</A></TD>
     <TD width="20" align="left"><A href="page.cfm?ID=#ID#&amp;username=#username#">Delete</A></TD>
     </TR>
     </CFLOOP>
</TABLE>
</cfmailpart>
<cfmailpart type="text">
text version here if you need it, otherwise delete this part
</cfmailpart>
</cfmail>

0
 
Tacobell777Commented:
ok ok then.. ;-)

<style>
div#layout table
{
      border: 1px solid black;
      font-family: tahoma, Arial, Helvetica, sans-serif;
      font-size: 10px;
}
caption
{
      font-size: 200%;
}

th a
{
      font-weight: bold;
}
</style>

<div></div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <caption>
  Click on Column Heading to sort
  </caption>
<thead>
  <tr>
    <th scope="col"><A href="page.cfm?username=#username#&orderby=name">Contact Name</A></th>
    <th scope="col"><A href="page.cfm?username=#username#&orderby=Company">Company</A></th>
    <th scope="col"><A href="page.cfm?username=#username#&orderby=email">E-Mail Address</A></th>
    <th scope="col">ETC.</th>
  </tr>
</thead>
<tbody>
<CFLOOP QUERY="Query">
  <tr>
    <td>#Query.Name#</td>
    <td>#Query.Company#</td>
    <td><A href="mailto:#Query.email#">#Query.email#</A></td>
    <td>ETC.</td>
  </tr>
</CFLOOP>
</tbody>
</table>

0
 
aftershoxCommented:
<CFSAVECONTENT Variable="EmailContent">
 .... your table code ....
</CFSAVECONTENT>

<CFMAIL to=".." from="..." subject="..." type="HTML">
#EmailContent#
</CFMAIL>
0
 
austintreAuthor Commented:
Ok, sorry I didn't get back to you until this morning, but mrichmon was correct and the easiest to use.  You cannot use CFOUTPUT within a CFMAIL tag.  However, CFLOOP worked.  So, hats off to mrichmon for giving me what I needed.  By the way your line <cfmailpart type="html">  does not work.  It didn't like it.  However, within your CFMAIL paramaters you specify the type.  So it should look like this:

<CFOUTPUT query="query" group="email">
    <CFMAIL TO="#email#"
            FROM="email@email.com"
            SUBJECT="subject line"
      TYPE="HTML"
      SERVER="mail.server.com"
      PORT="25">

Thank you for your comments.  I am going to study aftershox idea of CFSAVECONTENT  and tacobell your second idea went way over my head, but thanks for your help!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now