• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFMail 1 Message Multiple Names Dynamically

Community Beginner ,
May 23, 2007 May 23, 2007

Copy link to clipboard

Copied

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.
TOPICS
Advanced techniques

Views

460

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , May 23, 2007 May 23, 2007
Try the ValueList() function

Votes

Translate

Translate
Guide ,
May 23, 2007 May 23, 2007

Copy link to clipboard

Copied

Try the ValueList() function

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 24, 2007 May 24, 2007

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 23, 2007 May 23, 2007

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2007 May 24, 2007

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation