5 Replies Latest reply on Oct 5, 2006 11:42 AM by Dan Bracuk

    Looping

    Level 7
      I am having a problem with looping over a query.
      I have a query that contains all the people who have not opted out of a
      list. I want to send them an email. I am using the query to specifiy the
      loop, but I keep getting all the emails sent to the top address. I need it
      to step and repeat through each person. What am I doing wrong?

      <cfloop query="mailist">
      <cfmail from="#campaign.emailfrom#" to="#mailist.email#"
      replyto="#campaign.emailreply#" server="***" subject="#campaign.subject#">
      <cfmailpart type="html">
      <cfoutput>#campaign.html#</cfoutput>
      </cfmailpart>
      <cfmailpart type="text">
      <cfoutput>#campaign.plaintext#</cfoutput>
      </cfmailpart>
      </cfmail>
      </cfloop>


        • 1. Re: Looping
          Level 7
          Well that didn't seem to work too well. Each person on the list got 2 emails
          and the message was supposed to be 'hello' but was:

          'hello' on the first email and
          'hellohellohellohellohello' on the second second..

          There was a total of 4 people on the list...

          Help!

          cfif IsDefined ('Send_Mail')>
          <cfmail from="#campaign.emailfrom#" to="#mailist.email#"
          replyto="#campaign.emailreply#" server="***" subject="#campaign.subject#"
          query="mailist">
          <cfmailpart type="html">
          <cfoutput>#campaign.html#</cfoutput>
          </cfmailpart>
          <cfmailpart type="text">
          <cfoutput>#campaign.plaintext#</cfoutput>
          </cfmailpart>
          </cfmail>
          <cflocation url="done.cfm" addtoken="no">
          </cfif>



          • 2. Re: Looping
            Dan Bracuk Level 5
            Instead of cfloop, try using the query attribute of cfmail.
            • 3. Re: Looping
              Level 7
              Funny, that is the opposite of what adam told me. Atleast with that I was
              only getting one 'hello' in my body a bunch of the emails.

              When I tried to dump the variable that is being sent, I get two of them

              <cfloop query="mailist">
              <cfdump var="#mailist.email#">
              </cfloop>


              • 4. Re: Looping
                Level 7
                Nevermind. The email loop wasnt the problem. The inserting loop for the
                query insert is.


                • 5. Re: Looping
                  Dan Bracuk Level 5
                  What happens when you do this:
                  <cfdump var = "#mailist#">