Link to home
Start Free TrialLog in
Avatar of IShiva
IShiva

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of mkishline
mkishline

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IShiva
IShiva

ASKER

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.
Avatar of IShiva

ASKER

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>
Avatar of IShiva

ASKER

ok ill check those things and post back...Thanks!!!
Avatar of IShiva

ASKER

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>
Avatar of IShiva

ASKER

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! :-)
Avatar of IShiva

ASKER

Thanks!! I appreciate all your help!

IShiva