December 14th, 2003, 04:42 PM
Customising cfm mail messages
A simple question (I am hoping). Currently I am in the process of setting up a mailout form for my boss to send surveys, and he wants the ability to be able to specify several email addresses along with their corresponding name. So, in the form I have up to 5 input fields for the name, and another 5 for the appropriate email field. The fields are all matched accordingly - i.e. name1, email1, name2, email2 and so on (this is where my boss is to type the information). Initially I used a simple cfif to check to see the fields were defined before sending 'en mass' so to speak.....
<cfif IsDefined("form.email1") and isDefined("form.email2") and isDefined("form.email3")>
<cfset mailtarget = "#email1# ; #email2# ; #email3#;">
<cfelseif IsDefined("form.email1") and isDefined("form.email2")>
<cfset mailtarget = "#email1# ; #email2# ;">
<cfset mailtarget = "#email1#">
and then set mailtareget as the TO address.
This works fine, but does not allow me to assign a name to each individual email. I also know this is not the *correct* methodology and would prefer to use cfloop, where I check to see if email 1 is defined, then fetch name 1 and only THEN send, before moving on to the next series in the loop, until there are no more emails defined and the process halts. I also need this to work even if my boss only enters, for instance, 2 email addresses.
Any ideas? All help greatly appreciated.
December 15th, 2003, 11:13 AM
Are you sending out 5 seperate e-mails or 1 e-mail to 5 recipients?
Also - not sure what you mean by assigning a mail to each recipient.
My kneejerk (assuming 5 different e-mails) is to suggest having the user enter names 1 at a time and storing the names to a database or a session variable (array)
So your form would be a single name and e-mail, user clicks save, CF saves the info to an array, and forwards back to the entry form.
Once you have the info saved in an array/database, you can CFLOOP or CFQUERY through the list and send them individually.
Added advantage - no longer limited to 5 entries, boss can enter as many names as he likes.
Actually not that much coding, if I'm hitting on the issues let me know and we can play with some examples...
December 15th, 2003, 04:58 PM
Thank you for your reply estekguy. During the process of messing around and investigating cfloop further, I managed to work out an acceptable solution. In short to answer your question, I wanted it to loop thru each email and send them one at a time (to customise). Here's what I've got.......
<cfprocessingdirective suppressWhiteSpace = "Yes">
<cfloop index="i" from="1" to="3">
<cfif isDefined("form.name"&i) and isDefined("form.email"&i)>
<cfset customer_name = '#evaluate("form.name"&i)#'>
email content here
Seems to work for me!