Coldfusion - CFMail Error - Creating To: List and BCC: List

954 views Asked by At

For CFMail - I am building a To: list and BCC: list using cfset tolist and cfset bcclist

These output just fine. But when I add them into the cfmail - the tolist and bcclist error.

I am not sure why, as they are just comma delimited lists.

Get: The value of the attribute to, which is currently [email protected],[email protected],[email protected] is invalid.

When I hard code in the above list - it works just fine.

The alist and clists below create just fine, and look just fine to me. I can't seem to find a solution to what I'm doing wrong.

 <cfoutput>
 <cfif isdefined("form.checkbox1")><cfset clist = "#checkbox1#"></cfif>
 <br><br>Check List #clist#
 </cfoutput>

 To:
 <cfset tolist = "#clist#,<cfif alist is not "">#alist#,</cfif><cfif len(other)>#other#</cfif>">
 <cfoutput>#tolist#</cfoutput>

 BCC List - basically the same

 <cfoutput>
 <cfmail type="html" from="[email protected]" to="#tolist#" bcc="#bcclist#" mimeattach="#pdfpath#file.pdf" subject="File.pdf">

 Blahhh
 </cfmail>
 </cfoutput>
1

There are 1 answers

2
Matt Busche On BEST ANSWER

I would suggest re-writing your code to scope your variables and also to remove the if statements from inside the cfset statements. Also, I'm assuming this isn't all of your code since tolist and bcclist are never set anywhere. Try the code below.

<cfset tolist = '' />
<cfset bcclist = '' />
<cfoutput>
 <cfif StructKeyExists(form,'checkbox1')>
  <cfset clist = form.checkbox1 />
 </cfif>
 <br><br>Check List #clist#
</cfoutput>

To:
<cfif Len(Trim(alist))>
 <cfset tolist = ListAppend(tolist,alist) />
</cfif>
<cfif Len(Trim(other))>
 <cfset tolist = ListAppend(tolist,other) />
</cfif>

<cfoutput>#tolist#</cfoutput>

<cfmail type="html" from="[email protected]" to="#tolist#" bcc="#bcclist#" mimeattach="#pdfpath#file.pdf" subject="File.pdf">
Blahhh
</cfmail>