I'm having an odd problem sending e-mail using cfmail with a query
param. It is supposed to send a single e-mail which contains the
resultset from a database query (the contents of a shopping cart).
What's happening, however, is that it is sending 1 email per record in
the resultset, where the first e-mail contains the first record, the
second contains both the first and second records, the third contains
the first 3 records etc. Has anyone else seen this behavior?
It's a low volume online store so the mail server's not getting
thrashed. Where would you begin troubleshooting, or would you just
stuff the cart into a single var and output it in one shot? While
this is a tempting, quick fix, exprience tells me it's better to
address the issue because you never know what else will go hinky when
you ignore oddities like this.
This code, simplified for brevity, has worked without issue for many
years:
<cfmail query="qName" to=...>
Thanks for your purchase #valued_customer_name#
<cfoutput>
Item: #product_name#
qty: #how_many#
price: #DollarFormat(unit_cost)#
total: #DollarFormat(VAL(how_many) * VAL(unit_cost))#
</cfoutput>
Shipping and Handling: #DollarFormat(shipping_charge)#
etc
</cfmail>
Your thoughts are appreciated.
>> Ken Clarke
>> Contract Web Programmer / E-commerce Technologist
The query would be something like
SELECT product_name, how_many, unit_cost
FROM shoppingcart
WHERE cartid = "#session.usercartid#"
Here is an actual example from a few hours ago. The first e-mail
contained only 1 record. It should not have been sent:
=============
Your Order:
Item: twin or full size softside bed
Qty: 1
Size: Full
Unit Price: $99.95
Product Total: $99.95
Shipping and Handling: $0.00
SubTotal: $879.95
Total: $879.95
==========
The second e-mail, which contained 2 records, was the correct e-
mail. This was the only message which should have been sent.
======================
Your Order:
Item: Plush top Softside Waterbed with Free Flow Tubes
Qty: 1
Size: Full set (mattress and foundation)
Unit Price: $780.00
Product Total: $780.00
Item: twin or full size softside bed
Qty: 1
Size: Full
Unit Price: $99.95
Product Total: $99.95
Shipping and Handling: $0.00
SubTotal: $879.95
Total: $879.95
==============
Notice that the values outside the loop are correct (they are
calculated before entering cfmail), but they only appear correct in
the second e-mail. It appears that the cfoutput is erroneously
triggering the sending of the message after each iteration.
~Brad
Sent from my ASUS Eee Pad
On Nov 29, 12:53 am, Azadi Saryev <azadi.sar...@gmail.com> wrote:
> if you query does not contain email recipients - do not use it in query
> attribute in cfmail tag:
This method of outputting a recordset into a single e-mail is right
out of the developer manual. See http://perlprogrammer.net/query_based_email.pdf
It's page 1196 of "Developing Adobe ColdFusion 9 Applications". The
"Reviewing the code" section explains exactly why this works.
This worked for a decade (well, the original developers wrote the site
in CF5, whatever era that was :).
The work around suggested by Azadi Saryev to move the query parameter
from the cfmail tag to the cfoutput tag seems to solve the problem.