makila
asked on
CFMAIL sending email twice!
Hi,
I created an online library where people can check out books etc. I have a section where the library owner can send emails to the people whose books are overdue. However, whenever that process is run, two emails are sent to each person. I have no clue what could cause this.
I have a cfquery that grabs the information for the people who are overdue. Then I call the query within my cfmail. Here's the code:
<cfquery name="qryOverdue" datasource="library">
SELECT Loans.LoanIndex, Loans.Title, Loans.Name, Loans.Email, Loans.Date_Out, Loans.Date_Due
FROM Loans
WHERE ((Now()>[Loans]![Date_Due] ))
</cfquery>
<cfmail
to="#qryOverdue.Email#"
from="library_mailbox@comp any.com"
subject="overdue learning library item"
query="qryOverdue"
server="company_exchange_s erver.com"
port="25"
type="html">
<cfmailparam name="X-Priority" value="1">
Greetings,<p>
The item you checked out on #DateFormat(qryOverdue.Dat e_Out, 'mm/dd/yyyy')#,
"#qryOverdue.Title#", was due back #DateFormat(qryOverdue.Dat e_Due, 'mm/dd/yyyy')#.<p>
Please return this item to the Learning Library ASAP.<p>
Thank you!
</cfmail>
I created an online library where people can check out books etc. I have a section where the library owner can send emails to the people whose books are overdue. However, whenever that process is run, two emails are sent to each person. I have no clue what could cause this.
I have a cfquery that grabs the information for the people who are overdue. Then I call the query within my cfmail. Here's the code:
<cfquery name="qryOverdue" datasource="library">
SELECT Loans.LoanIndex, Loans.Title, Loans.Name, Loans.Email, Loans.Date_Out, Loans.Date_Due
FROM Loans
WHERE ((Now()>[Loans]![Date_Due]
</cfquery>
<cfmail
to="#qryOverdue.Email#"
from="library_mailbox@comp
subject="overdue learning library item"
query="qryOverdue"
server="company_exchange_s
port="25"
type="html">
<cfmailparam name="X-Priority" value="1">
Greetings,<p>
The item you checked out on #DateFormat(qryOverdue.Dat
"#qryOverdue.Title#", was due back #DateFormat(qryOverdue.Dat
Please return this item to the Learning Library ASAP.<p>
Thank you!
</cfmail>
ASKER
I should also add this tidbit. I replaced #qryOverdue.Email# with my own email and still received two emails for each overdue item.
are you sure your query is only returning 1 record? try dumping the recordset to see what's being returned
<cfdump var="#qryOverdue#">
<cfdump var="#qryOverdue#">
ASKER
I will try that when I get back to work on Monday :)
You probably need to group your query in the mail tag, look at the cfmail attribute GROUP
ASKER
The query is returning 10 unique records now (books have been returned!) and sending 20 emails. I upgraded to Coldfusion MX 6.1 in hopes that maybe it was a server bug but no such luck. I checked the mailsent.log and it shows 20 emails being sent.
I Googled to see if anyone else has had the same problems and I found a couple others but they never found resolutions.
I Googled to see if anyone else has had the same problems and I found a couple others but they never found resolutions.
ASKER
Previous message is referring to the results I got from dumping the recordset, btw. I also tried grouping the query in the mail tag by "LoanIndex" but I still got 20 emails. Ack.
is the mail tag wrapped in another custom tag? If so, does this tag end with \> ?
ASKER
I kind of have it figured out now. Somehow, the way I linked to the page with cfmail made it run twice.
This simple link works and it only emails once:
Click <a href="library_overdue_II.c fm">here</ a> to send an email reminder to all overdue loanees.
This link pops up a small window and after the cfmail sends, the windows says "Reminders have been sent." This sends the emails twice:
Click <a href="library_overdue_II.c fm" target="send_reminders" onClick="window.open('libr ary_overdu e_II.cfm', 'send_remi nders','wi dth=500,he ight=325,t op=150,lef t=200,tool bar=0,loca tion=0,dir ectories=0 ,status=0, menuBar=0, scrollBars =0,resizab le=1')" class="no_under">here</a> to send an email reminder to all overdue loanees.
This simple link works and it only emails once:
Click <a href="library_overdue_II.c
This link pops up a small window and after the cfmail sends, the windows says "Reminders have been sent." This sends the emails twice:
Click <a href="library_overdue_II.c
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SELECT Loans.LoanIndex, Loans.Title, Loans.Name, Loans.Email, Loans.Date_Out, Loans.Date_Due
FROM Loans
WHERE ((Now()>[Loans]![Date_Due]
</cfquery>
<cfoutput query="qryOverdue">
sending mail to #qryOverdue.Email#<br> <!--- this is just for debugging --->
<cfmail
to="#qryOverdue.Email#"
from="library_mailbox@comp
subject="overdue learning library item"
server="company_exchange_s
port="25"
type="html">
<cfmailparam name="X-Priority" value="1">
Greetings,<p>
The item you checked out on #DateFormat(qryOverdue.Dat
"#qryOverdue.Title#", was due back #DateFormat(qryOverdue.Dat
Please return this item to the Learning Library ASAP.<p>
Thank you!
</cfmail>
</cfoutput>