Highlighted

CFINCLUDE inside CFMAIL

New Here ,
Jul 13, 2014

Copy link to clipboard

Copied

I have a done a CFQUERY and retrieve user's email and name.  Then I try to do a CFMAIL something like:

<cfmail to="#user.email#" from="sender@somewhere.com" subject="Message from #sender_name#" type="html">

<table><tr><td>

Dear #receiver_name#

</td></tr>

<tr><td>

#form.message#

</td></tr>

</table>

</cfmail>

This seems to work with CFMAIL and the variables are being populated properly.  However, when I placed the content into a template content.cfm because I want to use it somewhere else as well. So content.cfm has:

<table><tr><td>

Dear #receiver_name#

</td></tr>

<tr><td>

#form.message#

</td></tr>

</table>

and the program became:

<cfmail to="#user.email#" from="sender@somewhere.com" subject="Message from #sender_name#" type="html">

<cfinclue template="content.cfm">

</cfmail>

Now the problem is, I am NOT getting the variables (#receiver_name# and#form.message#) populated by Coldfusion when I use the cfinclue template.  Why?  This is driving me crazy.  I don't know why it doesn't work.    Thanks in advance.

Adobe Community Professional
Correct answer by BKBK | Adobe Community Professional

Your code works in cfmail because Coldfusion performs cfoutput implicitly within the cfmail tag. The solution is therefore to add the cfoutput tag in content.cfm, as follows:

<cfoutput>

<table><tr><td>

Dear #receiver_name#

</td></tr>

<tr><td>

#form.message#

</td></tr>

</table>

</cfoutput>

Incidentally, your post has a typo: cfinclue instead of cfinclude. This is just a typo to get out of the way, and has nothing to do with the issue.

Views

664

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

CFINCLUDE inside CFMAIL

New Here ,
Jul 13, 2014

Copy link to clipboard

Copied

I have a done a CFQUERY and retrieve user's email and name.  Then I try to do a CFMAIL something like:

<cfmail to="#user.email#" from="sender@somewhere.com" subject="Message from #sender_name#" type="html">

<table><tr><td>

Dear #receiver_name#

</td></tr>

<tr><td>

#form.message#

</td></tr>

</table>

</cfmail>

This seems to work with CFMAIL and the variables are being populated properly.  However, when I placed the content into a template content.cfm because I want to use it somewhere else as well. So content.cfm has:

<table><tr><td>

Dear #receiver_name#

</td></tr>

<tr><td>

#form.message#

</td></tr>

</table>

and the program became:

<cfmail to="#user.email#" from="sender@somewhere.com" subject="Message from #sender_name#" type="html">

<cfinclue template="content.cfm">

</cfmail>

Now the problem is, I am NOT getting the variables (#receiver_name# and#form.message#) populated by Coldfusion when I use the cfinclue template.  Why?  This is driving me crazy.  I don't know why it doesn't work.    Thanks in advance.

Adobe Community Professional
Correct answer by BKBK | Adobe Community Professional

Your code works in cfmail because Coldfusion performs cfoutput implicitly within the cfmail tag. The solution is therefore to add the cfoutput tag in content.cfm, as follows:

<cfoutput>

<table><tr><td>

Dear #receiver_name#

</td></tr>

<tr><td>

#form.message#

</td></tr>

</table>

</cfoutput>

Incidentally, your post has a typo: cfinclue instead of cfinclude. This is just a typo to get out of the way, and has nothing to do with the issue.

Views

665

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 13, 2014 0
Engaged ,
Jul 14, 2014

Copy link to clipboard

Copied

Try this (usually at this point I'd have two versions, HTML and plaintext):

<cfsavecontent variable="content"><cfinclude template="content.cfm"></cfsavecontent>

<cfmail to="#user.email#" from="sender@somewhere.com" subject="Message from #sender_name#" type="html">

  <cfmailpart type="html">#content#</cfmailpart>

</cfmail>

Also wrap content.cfm inside <cfoutput></cfoutput>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 14, 2014 0
Adobe Community Professional ,
Jul 14, 2014

Copy link to clipboard

Copied

Your code works in cfmail because Coldfusion performs cfoutput implicitly within the cfmail tag. The solution is therefore to add the cfoutput tag in content.cfm, as follows:

<cfoutput>

<table><tr><td>

Dear #receiver_name#

</td></tr>

<tr><td>

#form.message#

</td></tr>

</table>

</cfoutput>

Incidentally, your post has a typo: cfinclue instead of cfinclude. This is just a typo to get out of the way, and has nothing to do with the issue.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 14, 2014 0