harters 0 Newbie Poster

Hello everyone. As the name suggests i am trying to figure out in CF9 over MySQL how to send multiple emails based on selected records from a grid.

I have a table called sstblemailnewmembers
this has fields:
fldemailid (Int + Auto Incr)
fldemail (TEXT)
fldsent (DATE)
CHECKED (SET 'true','false' DEFAULT false)

I then have a cf query in my page called emailnewmembers.cfm

<cfquery name="emailnewmembers" datasource="SAPLIVE">
SELECT fldemailID, fldemail, fldsent, CHECKED
FROM sstblemailnewmembers
</cfquery>

So far so good (i think)

I then have a form defined:

<cfform action="AdminTransfer.cfm"
width="1170"
method="post"
enctype="multipart/form-data"
format="Flash"
preloader="true"
style="backgroundAlpha: 0;"
wmode="transparent"
timeout="3000"
name="adminhome"
onload="loadAS();">

the onload="loadAS();" bit is used so I can select multiple records using this script which is the next bit to be defined:

<cfformitem type="script">
function loadAS(){
_root.myGrid.multipleSelection = true;
}
</cfformitem>

and finally on this page we have the grid itself and the submit button as below:

<cfgrid name="myGrid"
selectmode="edit"
query="emailnewmembers"
rowheaders="no">
<cfgridcolumn name="CHECKED" header="Select" type="boolean">
<cfgridcolumn name="fldemailID" header="Email ID">
<cfgridcolumn name="fldemail" header="Email Addrerss">
<cfgridcolumn name="fldsent" header="Date Sent">
</cfgrid>
<cfinput type="submit"
name="sendemailnewmembers"
value="Send Emails"
style="#buttonStyle#">

So far so good i guess?

The submit button calls the action page defined in the form tag.
This is what I have so far defined in the action page "admintransfer.cfm"...

<cfif isdefined("FORM.endemailnewmembers")>
<cfloop index = "Counter" from = "1" to =
#arraylen(Form.emails.CHECKED)#>

<cfif Form.emails.CHECKED[counter] is "true">
<cfquery name="emailnewmembers"
datasource="SAPLIVE">
UPDATE sstblemailnewmembers
SET
fldsent = NOW()
</cfquery>

<cfmail 
to = "#Form.fldemail#"
from = "myemailaddress@mydomain.com"
subject = "Welcome New Member">
Dear New Member...
</cfmail>
</cfif>
</cfloop>
</cfif>

So, my issue is that if I select 3 records an email is getting sent 3 times to the last email address of the last record I select rather than 3 individual emails to 3 members

I am assuming there is something wrong with the loop and probably a better way to do this but I am quite new and this is the best I can come up with so if anyone cares to point me in the right direction I would be enormously grateful indeed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.