0

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 emailthis@gmail.com,emailthat@gmail.com,emailagain@gmail.com 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="bob@bob.com" to="#tolist#" bcc="#bcclist#" mimeattach="#pdfpath#file.pdf" subject="File.pdf">

 Blahhh
 </cfmail>
 </cfoutput>
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Merle_the_Pearl
  • 1,391
  • 3
  • 18
  • 25
  • 1
    What is the output from your to list? I have never seen a cfif used in that context. Seems to me it would add that code to your tolist variable – Matt Busche May 28 '12 at 18:37
  • 1
    They are outputing just fine - #tolist# is outputing to the page so I can see how it looks. I also have pulled the front < off of the cfmails to see what it looks like inside the cfmail without sending - all seems fine – Merle_the_Pearl May 28 '12 at 18:40
  • is clist or other a blank variable? if so you have a leading or trailing comma that you shouldn't. – Matt Busche May 28 '12 at 19:04
  • I'm surprised that you didn't get errors by embedding a `` inside a `` like that. – ale May 29 '12 at 17:18

1 Answers1

3

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="bob@bob.com" to="#tolist#" bcc="#bcclist#" mimeattach="#pdfpath#file.pdf" subject="File.pdf">
Blahhh
</cfmail>
Matt Busche
  • 14,216
  • 5
  • 36
  • 61
  • Seems to work - I'll keep testing - what was I doing wrong? I agree maybe had extra , in there - but when I hard coded that in - it emailed fine with extra , in there - looks like this is the answer - thx – Merle_the_Pearl May 28 '12 at 19:16
  • 1
    i would assume the issue was with the extra , It shouldn't have worked if you hardcoded it in their either, but I suppose it's possible. If this solved your issue please mark this question an answered. – Matt Busche May 28 '12 at 19:24