Sending emails to checked address only

I have a database table that holds info about players on a soccer team. Name, Number, Position etc. I added the field 'PlayerEmail' to the table. After the coach logs in, I want him to be able to send emails to the entire team OR to individual players that he checks. (I would have a 'Send to all' link, a 'Send to Varsity' link and a 'Send to Junior Varsity' link at the top of the page so he doesn't have to check 20some boxes to send emails to a particular team. He does need the ability to send an email to just 1 or 2 players though, and I'm a bit stumped. I would like the coach to be able to check 1 or some of the players then be sent to a page with a form (textarea) where he can then type his email. He would then click send, and the email would only be sent to the checked players. In my mind this would have to be 3 pages.....ViewPlayers.cfm (where the player info and the 'send email to' checkbox would be)......ComposeEmail.cfm (where the coach would type in a textarea to provide the email content).....and the ComposeMailAction.cfm (where the cfmail would execute and mail to only checked players)  I know how to code the 'Send to Varsity' or 'Send to All' piece, and am have a little bit of knowledge on cfmail but am baffled when it comes to checkboxes. Does anyone have an idea? Your help is appreciated.

IShiva
IShivaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mkishlineCommented:
If you give all the checkboxes the same name, the form will place them all in one field as a comma-delimited list.

<!--- ViewPlayers.cfm --->
<cfoutput query="team">
  <input type="checkbox" name="emailPlayer" value="#PlayerEmail#" />#firstname# #lastname#<br />
</cfoutput>

<!--- ComposeEmail.cfm --->
<input type="hidden" name="emailPlayer" value="#form.emailPlayer#" />

<!--- ComposeMailAction.cfm --->
<cfmail to="#form.emailPlayer#" ....

or

<cfloop index="i" list="#form.emailPlayer#">
  <cfmail to="#i#" ...
  </cfmail>
</cfloop>

Since it will be a comma-delimited list, you can just leave it as the entire To section of the email or you can loop through it and send the emails individually.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IShivaAuthor Commented:
Thanks for the reply. Are there any cfquery's on those pages?
0
mkishlineCommented:
You'd need a cfquery on ViewPlayers.cfm to pull the names and email addresses of the players so you can output them. Other than that, you'd only need a cfquery if you need information that won't be provided by the user through the forms. Keep in mind that any information you want to pass from ViewPlayers.cfm to ComposeMailAction.cfm needs to be passed from ViewPlayers.cfm->ComposeEmail.cfm->ComposeMailAction.cfm.  ComposeMailAction.cfm cannot directly access any form or other variables from ViewPlayers.cfm.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

IShivaAuthor Commented:
ok, can you please doublecheck my code below. It goes through just fine without error, but no emails are sent. Is my code incorrect?

<--- SendEmailAction.cfm -->

<cfloop index="i" list="#form.PlayerEmail#">

<cfmail to="#i#"
from="myemail@domain.com
subject="#form.Subject#" type="html">

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table>

email content will go here

</body>
</html>


</cfmail>
</cfloop>


<cflocation url="ThankYou.cfm">
0
mkishlineCommented:
Your table is not quite right, (missing <tr><td> and ending </table>) but I doubt that is the cause of the problem. For testing purposes, try changing your code on the SendEmailAction page to this:

<cfloop index="i" list="#form.PlayerEmail#">
  Send email to: #i#<br />
</cfloop>
<cfabort />

If the email addresses don't show up on the page, then change the code to:

<cfdump var="#form#" />
<cfabort />

Check the PlayerEmail field and see what, if any values are being passed into that. If the value in PlayerEmail is #form.PlayerEmail# then on ComposeEmail.cfm make sure that your <input type="hidden" name="PlayerEmail" value="#form.PlayerEmail#" /> tag is wrapped inside of a <cfoutput>
0
IShivaAuthor Commented:
ok ill check those things and post back...Thanks!!!
0
IShivaAuthor Commented:
I didn't have <input type="hidden" name="PlayerEmail" value="#form.PlayerEmail#" /> surrounded in a <cfoutput>. Works perfect now!!

One last thing, on the ComposeEmail.cfm page I have a textbox and textarea where the coach types the email. I also have a list of the recipients that he has chosen from the previous page. I cant seem to get that list to go up and down. It is a comma delimited list and makes my page very wide. Is there a way to view the comma delimited list up and down? Like in multiple <tr>'s? Here is my code for that section. I even tried surrounding the <tr> in a cfoutput but that didnt work either. Any suggestions on this?

<table cellpadding="2" cellspacing="0">
    <tr>
       <td><strong>Email recipients:</strong></td>
    </tr>
    <tr>
       <td><font size="-2"><cfoutput><br>#form.PlayerEmail#</cfoutput></font></td>
    </tr>
</table>
0
mkishlineCommented:
This should work:

<table cellpadding="2" cellspacing="0">
    <tr>
       <td><strong>Email recipients:</strong></td>
    </tr>
    <tr>
       <td><font size="-2"><cfoutput><cfloop index="i" list="#form.PlayerEmail#">#i#<br /></cfloop></cfoutput></font></td>
    </tr>
</table>
0
IShivaAuthor Commented:
how bout that....i actually figured that one out on my own.....here is what i did..can you tell me if this is acceptable? It works, but will it give me problems later on?

<cfset list = "#form.PlayerEmail#">
   <td valign="top">
      <table cellpadding="2" cellspacing="0">
        <tr>
            <td><strong>Email recipients:</strong></td>
        </tr>
        <cfloop list="#list#" index="i">
        <tr>
            <td><font size="-2"><cfoutput>#i#</cfoutput></font></td>
        </tr>
        </cfloop>
      </table>
   </td>
0
mkishlineCommented:
No problems with that at all. Well done and happy coding! :-)
0
IShivaAuthor Commented:
Thanks!! I appreciate all your help!

IShiva
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.