4 Replies Latest reply on May 24, 2007 9:21 AM by Dan Bracuk

    CFMail 1 Message Multiple Names Dynamically

    twodaend Level 1
      Is there a way to send a mail message to multiple users. I tried using the query tag, but that will send a message to each person without the other names being listed in the two field. What I want to do is have a variable that contains every person to send it to and use that variable to send the message. For example the to field would contain user1@aol.com, user2@aol.com.

      I have the user info in the DB and I'm doing a query to return the name. The only problem is that I can't make a list of name. So far I have:
      <cfquery name="AllEmailAddress" datasource="#Application.dsn#">
      SELECT email
      FROM Users
      </cfquery>

      <cfmail to="user1@aol.com" from="#form.senderemail#" subject="#form.subject#" >
      #form.body#
      </cfmail>

      What I though I could do was:

      <cfmail to="#AllEmailAddress.email from="#form.senderemail#" subject="#form.subject#" >
      #form.body#
      </cfmail>

      but that does not work. Is there a way to get all of the names in a list i.e <cfset all=user1@aol.com, user2@aol.com>, but doing that dynamically? From there I could use that variable to use in the to field. I think I know what I want to do, but I can't think of the code to do it.
        • 1. Re: CFMail 1 Message Multiple Names Dynamically
          cf_dev2 Level 1
          Try the ValueList() function
          • 2. Re: CFMail 1 Message Multiple Names Dynamically
            efecto747 Level 1
            I haven't tried this but apparently you can send to multiple email addresses from a query (as you're trying to do) by using the "query" attribute in cfmail to specify the name of your query and then put the column name (with hash symbols) in the "to" attribute.

            So your cfmail tag would look something like this:

            <cfmail query="AllEmailAddress" to="#email#" from="#form.senderemail#" subject="#form.subject#" >
            #form.body#
            </cfmail>

            For more info on the cfmail tag, have a look in LiveDocs
            • 3. Re: CFMail 1 Message Multiple Names Dynamically
              twodaend Level 1
              Using the valuelist worked great. I tried adding the delimiter but that did not work. Just using valuelist() and letting it insert the comma on its own works perfect.

              <cfquery name="AllEmailAddress" datasource="#Application.dsn#">
              SELECT email
              FROM Users
              </cfquery>

              <cfmail to="#ValueList(AllEmailAddress.Emal)#" subject="#form.subject#" >
              #form.body#
              </cfmail>
              • 4. Re: CFMail 1 Message Multiple Names Dynamically
                Dan Bracuk Level 5
                quote:

                Originally posted by: efecto747
                I haven't tried this but apparently you can send to multiple email addresses from a query (as you're trying to do) by using the "query" attribute in cfmail to specify the name of your query and then put the column name (with hash symbols) in the "to" attribute.

                So your cfmail tag would look something like this:

                <cfmail query="AllEmailAddress" to="#email#" from="#form.senderemail#" subject="#form.subject#" >
                #form.body#
                </cfmail>

                For more info on the cfmail tag, have a look in LiveDocs

                This method works differently than the one that uses valuelist. This method sends individual mails to each person while the valuelist method sends one mail to several people.

                Pick the one that best meets your requirements.