Copy link to clipboard
Copied
Hi... Im using cfmail (CF8) on a CFC, to allow users to sent email from a big mailing list.
It was working fine, but Today, two users started to send their own e-mails at same time, but we recieve the emails mixed ...I mean the first email Subject, but with the second email Body, or the first body with the second Subject
Any Idea what should I Do?
Copy link to clipboard
Copied
Make sure that you are properly scoping your variables in your CFC. Use the 'var' keyword when you create variables used inside your CFC functions, even query names. Define all of your variables used inside the CFC immediately after any CFARGUMENT tags and before any other logic. Something like this pseudo-code:
<cffunction name="myFunction" ...>
<cfargument name="myArg1" ...>
<cfargument name="myArg2" ...>
<!--- Declare variables --->
<cfset var myVar = "">
<cfset var myQuery = "">
<!--- Function logic --->
</cffunction>
HTH,
-Carl V.
Copy link to clipboard
Copied
Make your code thread safe by wrapping it inside a cflock tag. See the documentation here: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f5d.html
Basically it will look something like this:
<cflock name="myEmailLock" type="exclusive" timeout="10">
<cfmail>
...
</cfmail>
</cflock>
By wrapping your cfmail code with an exclusive lock like this only one user can run that code at any given time. Note that this may introduce some timeout errors for other users trying to access this at the same time. You will need to deal with that. You may also want to include more code within the cflock tags depending on what you are doing.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now