Page 1 of 1

forgot password problem..

Posted: Thu May 19, 2005 2:14 pm
by Smackie
I got a script for people to have there username and password sent to them well for some reason it will send it out just by itself but when i add it to my template script it just says the email failed.. here is the script


forgot.php

Code: Select all

<?php
if(isset($_POST['submit']))
{
foreach( $_POST as $key => $value )
{
${$key} = htmlspecialchars($value);
}
mysql_connect("localhost","db","*******");
mysql_select_db(table);

// do som config
$sitename ="Webcom-Online";
$sitemail = "Admin@webcom-online.org";

$sql = mysql_query("SELECT * FROM users WHERE user_name='$name' AND email_address='$email'");

// if no single match
if(mysql_num_rows($sql) <> 1)
{
echo "The user name and email do not match.";
exit;
}
$fPass = mysql_fetch_array($sql);
$username = $fPass[user_name];
$password = $fPass[password];

// prepare email
$sendto = $email;
$from = $sitename;
$subject = "Your user info";
$message = "Here is your username and password.\nIf you didnt request it dont worry, your username and password only goes to your email box..\n\nUsername: $username\nPassword: $password\n\n\nYou requested the email from $sitename
";

// setting some headers to try and avvoid it as garbage mail
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "From: $sitename <$sitemail>\r\n";
$headers .= "Reply-to: $sitename <$sitemail>\r\n";
$headers .= "Return-Path: $sitename <$sitemail>\r\n";
$headers .= "X-MSMail-Priority: Low\r\n";
$headers .= "X-Mailer: php\r\n";

// do send
mail($sendto, $subject, $message, $headers, "-f" . $sitemail) or die('Email failed');

print "Your Password has been sent to $sendto";

}
?>
<center>
<form action="<?= $PHP_SELF ?>" method="post">
Name: <input type="text" name="name" size="24" border="0"><br>
E-mail: <input type="text" name="email" size="24" border="0"><br>
<input type="hidden" name="go" value="1" border="0"><input type="submit" name="submit" value="request email" border="0">
</form></center>
can someone find what can be the problem?

Thanx
Smackie

Posted: Thu May 19, 2005 2:23 pm
by shiznatix
if(mysql_num_rows($sql) <> 1)
first off i THINK thats only VB compatable i think > 0 is the best way to do the if 0 or more.

also i THINK the mail function only supports 4 paremeters, $to, $subject, $message, $header

you have 5 parameters with the , after $header...that might be causeing your error.

these are just maybes and i dont know for sure

Posted: Thu May 19, 2005 2:26 pm
by Smackie
i dont get an error it just saying the mail failed well i guess it would be an error but it works just fine if i dont have it on any other page but when i put it on my template it just say mail failed

Posted: Thu May 19, 2005 2:31 pm
by Smackie
here you can test it yourself

go to http://www.webcom-online.org/login/forgot.php

and use

username: test
email: test@webcom-online.org

then go to http://www.webcom-online.org/index.php?pages=forgot

and use the same username and email