1 Reply Latest reply on Jan 29, 2007 9:03 AM by azadisaryev

    Splitting up email addresses by comma's

    NDWebDeveloper
      I am trying to input info into a database and I have a mailer form above it that supports multiple addresses. Someone suggested the trim option used below to seperate each line with info however that doesn't work. I wish to use all the same info in teh database entry however only put 1 email address per entry even if 5 are used.
        • 1. Re: Splitting up email addresses by comma's
          azadisaryev Level 1
          if i understand you correctly, you want to insert only ONE email address into your db, even if the entry field contains several comma-separated emails? do not <cfloop> through the for.recipiants list then. instead use, for example, '#ListFirst(form.recipiants)#' instead of '#trim(thisAddress)#' in your INSERT query.

          however, if what you want to do is insert A SEPARATE RECORD for EACH EMAIL ADDRESS in the list, then you have to do something like (NOTE: i am assuming form.email is a comma-delimited list of recepients and form.recipiants is a comma-delimeted list of their names):
          <cfloop index="iii" from="1" to="#ListLen(form.recipiants)#">
          <cfquery name="updatetable" datasource="#------#">
          INSERT INTO send_to_friend (email, receivers_name, sendersname, sendersemail, message)
          VALUES ('#ListGetAt(form.email, iii)#', '#ListGetAt(form.recipiants, iii)#', '#form.sendersname#', '#form.sendersemail#', '#form.message#')
          </cfquery>
          </cfloop>

          IMPORTANT: you will have to implement some serious validation here to check that the lists of emails/names have more than one item and that number of items in both lists match!!!