3 Replies - 1756 Views - Last Post: 07 February 2012 - 09:38 AM Rate Topic: -----

#1 matttolman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-February 12

Question sending a form via cfmail to adresses depending on last name

Posted 06 February 2012 - 04:07 PM

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. 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.

    <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.

Is This A Good Question/Topic? 0
  • +

Replies To: Question sending a form via cfmail to adresses depending on last name

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: Question sending a form via cfmail to adresses depending on last name

Posted 07 February 2012 - 07:55 AM

Welcome to DIC matttolman!

I'm not sure we can help you as you haven't really described a particular problem as yet. Looking at the code sample you included, I can tell you your IF checks are going to fail though. Taking the first one, for example:
<cfif Left(form.LAST_NAME, A,B,C,D,E,F,G,H)>

...it looks like you're wanting to email something if the first letter of the last_name in the form struct is A through H, right? If so, you'll need somewhat different code. The easiest thing to do is to isolate that first character of form.last_name:
<cfset variables.firstLetter_LN = Left(Trim(form.last_name),1)>

...then do some if checks against that:
<cfif ListFindNoCase("A,B,C,D,E,F,G,H",variables.firstLetter_LN) NEQ 0>


The first code block isolates the first letter of the last_name. The LEFT function in CF requires two parameters: the value to evaluate and the number of leftmost positions to return. There's also a TRIM function in there to remove any leading or trailing spaces. That's to ensure that the LEFT function doesn't return a blank space when you run it.

The second code block uses the ListFindNoCase function to search a list for a particular value...in the example, that value is the derived character from the TRIM and LEFT functions on the form.last_name variable. You'd simply adjust the CFIF to a CFELSEIF for comparisons to other lists of letters as you need to. Understand that in a CFIF/CFELSEIF series that the first block that comes back with a match is the block that will be executed and the remainder will be skipped.

After that, you send your email via the CFMAIL tag as your app requires.

Hope that helped some. If not, post back here and we'll be glad to see what we can do. Good luck!

This post has been edited by Craig328: 07 February 2012 - 07:55 AM

Was This Post Helpful? 1
  • +
  • -

#3 matttolman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-February 12

Re: Question sending a form via cfmail to adresses depending on last name

Posted 07 February 2012 - 09:25 AM

Thank you so much Craig328! This is exactly what I am trying to do. It works like a charm. Also, thank you for taking the time to run through what the code actually does, it is a huge help to me in leaning and understanding ColdFusion.
Again, I appreciate the help.
Thank you.

-Matt-
Was This Post Helpful? 0
  • +
  • -

#4 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: Question sending a form via cfmail to adresses depending on last name

Posted 07 February 2012 - 09:38 AM

N/P. Glad to be of help.

As an aside, we have a very handy CF Resources thread that you can bookmark as your one-stop shop for ColdFusion resources. This forum is here to answer specific questions but 90% of the CF questions any beginner has can be answered with the contents of the resources thread.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1