query db and send output via email
| From: | Rodney Davis | Date: | Wed, 11 Oct 2000 20:08:55 +0000 |
| Subject: | query db and send output via email | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-19696@lists.php.net to get a copy of this message | ||
I wrote the following script to have users that have forgoten their
usernames
or passwords to enter their address and have that info sent to them. I want
the script to query the db find the appropriate info to the user with the
entered email address. Everything works except the email doesn't have the
$username and $password variables appended to it. they are left blank.
the $email variable gets printed but that is supplied by the user via a
form.
why would my while statement not asign the right values to $username
and $password?
Any and all advice apprciated.
##Forgot your password? Sends username and password based on e-mail
address.
function sendPassword ($email) {
global $link;//opens connection to mysql db
$result = mysql_query ("SELECT id, username, password, email FROM someDB
WHERE email='$email'", $link);
if (!$result)
die ("sendPassword fatal error: ".mysql_error());
if (mysql_num_rows ($result)) {
while ($var = mysql_fetch_array($result)) {
$username= $var["username"];
$password= $var["password"];
$msg = "something\n";
$msg .= "something_more \n\n";
$msg .= "username:\t\t$username \n";
$msg .= "password:\t\t$password \n";
$msg .= "mail address:\t$email \n";
$mailheaders = "From: Somewhere.com \n";
$mailheaders .= "Reply-To: someone@someplace.com \n\n";
if(mail ($email, "somewhere.com", $msg, $mailheaders)) {
print ("Mail successful! sent to $email");
} else {
print ("mail transmition failed");
}
}
} else die ("No username associated with that email");
return false;
}
Thanks,
rodney