#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Cfmail to certain addresses depending on form data


    I have a form I need to send via cfmail to certain addresses depending on the first letter of the last name on the form being submitted. I am a new to coldfusion in need of some help. not sure how to go about it. I have some code, but as I said I am new to coldfusion and was tasked with this project. I don't expect someone to do it for me, I just would appreciate some help of any kind.

    I am limited to Coldfusion 5 also.

    Code:
    <cfif Left(form.LAST_NAME, A,B,C,D,E,F,G,H)>
    	      <CFMAIL TO="person1@bob.org"
    	        FROM="#form.EMAIL#"
    	        etc...
    	      </CFMAIL>
    	<cfelseif Left(form.LAST_NAME, I,J,K,L,M,N,O,P)>
    	      <CFMAIL TO="person2@bob.org"
    	        FROM="#form.EMAIL#"
    	        etc...
    	      </CFMAIL>
    	<cfelseif Left(form.LAST_NAME, Q,R,S,T,U,V,W,X,Y,Z) >
    	      <CFMAIL TO="person3@bob.org"
    	        FROM="#form.EMAIL#"
    	        etc...
    	      </CFMAIL>
    	<cfelse>
    	      <CFMAIL TO="person4@bob.org"
    	        FROM="#form.EMAIL#"
    	        etc...
    	      </CFMAIL>
    	</cfif>

    Please Help! Thanks in advance.
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,264
    Rep Power
    968
    The first thing you'll want to do is check the docs, because that's not how the Left() function works.

    First I would simplify this with a basic regular expression, something like:

    Code:
     
    <cfif REFindNoCase("[a-h]", form.last_name)>...
    Second, you can avoid having to duplicate the entire cfmail tag by using a variable for the email address. So something like:

    Code:
    <!--- Default email --->
    <cfset email = "person4@bob.org" />
    
    <cfif REFindNoCase("[a-h]", form.last_name)>...
    	<cfset email = "person1@bob.org" />
    <cfelseif REFindNoCase("[i-p]", form.last_name)>
    	<cfset email = "person2@bob.org" />
    <cfelseif REFindNoCase("[q-z]", form.last_name)>
    	<cfset email = "person3@bob.org" />
    </cfif>
    
    <cfmail to="#email#".....>
    Hope that helps.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0
    Thank you so much for the help. This also helps me understand ColdFusion better too.

IMN logo majestic logo threadwatch logo seochat tools logo