Coldfusion 使用cfmail发送多封电子邮件
我知道我遗漏了一些非常小的东西,但我无法绕过这一点。我有以下疑问。 我需要3封电子邮件发送到各自的电子邮件,但发生的是只有相同的电子邮件(内容)发送到3个用户。 你知道这里出了什么问题吗Coldfusion 使用cfmail发送多封电子邮件,coldfusion,Coldfusion,我知道我遗漏了一些非常小的东西,但我无法绕过这一点。我有以下疑问。 我需要3封电子邮件发送到各自的电子邮件,但发生的是只有相同的电子邮件(内容)发送到3个用户。 你知道这里出了什么问题吗 <cfquery name = getitems > Select items, id, users from table1 </cfquery> This below query returns say 3 users <cfquery name = getusers >
<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>
选择项目、id、用户
来自表1
下面的查询返回3个用户
从表2中选择姓名、电子邮件、id
从getitems中选择*,其中id=#id#
构建电子邮件正文
这是一个更好的方法
<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>
选择姓名、电子邮件等
从table1连接table1.id=table2.id上的table2
等
这是一个更好的方法
<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>
选择姓名、电子邮件等
从table1连接table1.id=table2.id上的table2
等
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>
从表1中选择项目、id和用户
从表2中选择姓名、电子邮件、id
从getitems中选择*,其中id=#id#
构建电子邮件正文
向用户发送电子邮件
丹指出的方法是更好的方法,但我会指出你的代码出了什么问题。
运行循环并使用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>
从表1中选择项目、id和用户
从表2中选择姓名、电子邮件、id
从getitems中选择*,其中id=#id#
构建电子邮件正文
向用户发送电子邮件
为什么您在单独的循环中构建电子邮件正文而不是在发送电子邮件时?为什么您在单独的循环中构建电子邮件正文而不是在发送电子邮件时?