kenjpete
asked on
Including username and password in email dynamically
I am trying to figure out how to include a user's username and password in an email dynamically. I have an Access database that contains basic student information including first name, last name, username, password, email address, school and teacher. I want to query the database based on a parameter like teacher or school and then send an email to all students who meet that query. In the email I want to include the student's username and password. Here is my code:
**************
Query:
**************
<cfquery name="GetEmail_schools" datasource="#DataSource#">
SELECT StudentID, First, Last, Email, School, Username, PCode
FROM data
WHERE School = '#session.School#' AND Email IS NOT NULL
</cfquery>
****************
Code to send email:
****************
<cfmail
Type="HTML"
query="GetEmail_schools"
To="#Email#"
From="xxx@xxxx.com"
Subject="Your login information"
SERVER="127.0.0.1"
PORT="25"
>
<p>#First#,</p>
<cfloop query="GetEmail_schools">
<cfoutput>
Your username is: #GetEmail_schools.Username # <br>
Your password is: #GetEmail_schools.Pcode#
</cfoutput><br>
</cfloop>
</cfmail>
************************** *
The result when I load this page is that everyone gets a list of all usernames and passwords? How do I structure my code so an email recipient only sees their username/password?
Ken
P.S. I also tried removing the <cfloop> tags and using just <cfoutput> but the result was the same.
**************
Query:
**************
<cfquery name="GetEmail_schools" datasource="#DataSource#">
SELECT StudentID, First, Last, Email, School, Username, PCode
FROM data
WHERE School = '#session.School#' AND Email IS NOT NULL
</cfquery>
****************
Code to send email:
****************
<cfmail
Type="HTML"
query="GetEmail_schools"
To="#Email#"
From="xxx@xxxx.com"
Subject="Your login information"
SERVER="127.0.0.1"
PORT="25"
>
<p>#First#,</p>
<cfloop query="GetEmail_schools">
<cfoutput>
Your username is: #GetEmail_schools.Username
Your password is: #GetEmail_schools.Pcode#
</cfoutput><br>
</cfloop>
</cfmail>
**************************
The result when I load this page is that everyone gets a list of all usernames and passwords? How do I structure my code so an email recipient only sees their username/password?
Ken
P.S. I also tried removing the <cfloop> tags and using just <cfoutput> but the result was the same.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
lol, I guess I typed too slow =)
but it's always nice to reinforce a good idea ;-)
ASKER
Great! That appears to have worked perfectly. Now the question is who gets the 250 points? Can I divide it up evenly or do I have to take the solution that was dated first?
give it to mkishline since he gave the answer first.
**************
Query:
**************
<cfquery name="GetEmail_schools" datasource="#DataSource#">
SELECT StudentID, First, Last, Email, School, Username, PCode
FROM data
WHERE School = '#session.School#' AND Email IS NOT NULL
</cfquery>
****************
Code to send email:
****************
<cfmail
Type="HTML"
query="GetEmail_schools"
To="#Email#"
From="xxx@xxxx.com"
Subject="Your login information"
SERVER="127.0.0.1"
PORT="25"
>
<p>#GetEmail_schools.First
Your username is: #GetEmail_schools.Username
Your password is: #GetEmail_schools.Pcode#<b
</cfmail>
**************************