首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用cfmail发送多封电子邮件

使用cfmail发送多封电子邮件
EN

Stack Overflow用户
提问于 2014-08-14 04:20:18
回答 2查看 533关注 0票数 0

我知道我在这里遗漏了一些非常小的东西,但我不能绕过这个。我有以下疑问。我需要3个电子邮件去各自的电子邮件,但正在发生的是只有相同的电子邮件(内容)是发送给3个用户。知道这里出了什么问题吗。

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

发布于 2014-08-14 05:40:59

这是一种更好的方法。

代码语言:javascript
复制
<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>
票数 4
EN

Stack Overflow用户

发布于 2014-08-14 19:44:28

Dan指出的方法是做事情的更好的方法,但我会指出你的代码的问题所在。您运行循环并使用savecontent将所有值存储在单个变量中。现在,再次运行循环,将向所有用户发送相同的变量。

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25295385

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档