我知道我在这里遗漏了一些非常小的东西,但我不能绕过这个。我有以下疑问。我需要3个电子邮件去各自的电子邮件,但正在发生的是只有相同的电子邮件(内容)是发送给3个用户。知道这里出了什么问题吗。
<cfquery name = getitems >
Select items, id, users
from table1
</cfquery>
This below query returns say 3 users
<cfquery name = getusers >
Select name,email,id from table2
</cfquery>
<cfloop query=”getusers”>
<cfquery name = getuserdata dbtype=”query” >
Select * from getitems where id=#id#
</cfquery>
</cfloop>
<cfsavecontent variable=”test”>
<cfloop query=" getuserdata ">
<cfloop from="1" to="#arrayLen(itemsarray)#" index="ii">
Build the email body
</cfloop>
</cfloop
</cfsavecontent>
<cfloop query=”getusers”>
<cfmail >
Send email to users
</cfmail>
</cfloop>发布于 2014-08-14 05:40:59
这是一种更好的方法。
<cfquery name="theOnlyQueryYouShouldNeed">
select name, email, etc
from table1 join table2 on table1.id = table2.id
etc
</cfquery>
<cfmail query="theOnlyQueryYouShouldNeed"
to="#email#
etc>
build body here. You can output variables with pound signs
only, no cfoutput tag required
</cfmail>发布于 2014-08-14 19:44:28
Dan指出的方法是做事情的更好的方法,但我会指出你的代码的问题所在。您运行循环并使用savecontent将所有值存储在单个变量中。现在,再次运行循环,将向所有用户发送相同的变量。
<cfquery name = getitems >
Select items, id, users from table1
</cfquery>
<cfquery name = getusers >
Select name,email,id from table2
</cfquery>
<cfloop query=”getusers”>
<cfquery name = getuserdata dbtype=”query” >
Select * from getitems where id=#id#
</cfquery>
<cfsavecontent variable=”test”>
<cfloop query=" getuserdata ">
<cfloop from="1" to="#arrayLen(itemsarray)#" index="ii">
Build the email body
</cfloop>
</cfloop>
</cfsavecontent>
<!--- so basically, you need to send email within the same loop in which you are generating your savecontent variable--->
<cfmail >
Send email to users
</cfmail>
</cfloop>https://stackoverflow.com/questions/25295385
复制相似问题