We help IT Professionals succeed at work.

Sending emails to checked address only

IShiva
IShiva asked
on
Medium Priority
196 Views
Last Modified: 2013-12-24
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
Comment
Watch Question

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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks for the reply. Are there any cfquery's on those pages?
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.

Author

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">
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>

Author

Commented:
ok ill check those things and post back...Thanks!!!

Author

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

Author

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>
No problems with that at all. Well done and happy coding! :-)

Author

Commented:
Thanks!! I appreciate all your help!

IShiva
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.