I have recently created a website so that I can practice users registrations and user logins. Ive been successful with this however I now want to create a system whereby if a user forgot their password and wanted to find their password then the system would require the users username, would then check the password matched with the username in the mysql database and would then send the user an email with their password:
This is what I have tried so far however I keep getting an error message "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()" and does not send any email:
<!Doctype html>
<html>
<head>
<title>
Forget Password
</title>
<LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>
<body bgcolor="#872588" id="background">
</head>
<body>
<CENTER><img src="banner.png" alt="logo" id="logo"></CENTER>
<div id="navigation">
<ul>
<li><a href="home.html" id="child"><b><font style="Alan Den">Home</font></b></a></li>
<li><a href="about.html"><b><font style="Alan Den">About Stress?</font></b></a></li>
<li><a href="beat.html"><b><font style="Alan Den">Beating stress?</font></b></a></li>
<li><a href="enquiry.html" id="parent"><b><font style="Alan Den">Contact us!</font></b></a></li>
</ul>
</div>
</br>
<div id="box201">
<form name="forgot" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<h1><font color="pink">Forget Password Form</font></h1>
<p><font color="white">(Please fill in your username which you used to register with when registering on to this website.)</font></p>
<p><label for="username">Username:</label>
<input name="username" type="text" value="" />
</p>
<br>
<input type="submit" name="submit" value="submit"/>
<input type="reset" name="reset" value="reset"/>
</form>
</div>
<?php
if(isset($_POST['submit']))
{
mysql_connect("localhost", "root", "Fatiuma1234") or die(mysql_error());
mysql_select_db("login") or die(mysql_error());
$username = $_POST['username'];
$sql = "SELECT `email`, `password` FROM `users` WHERE `username` = '$username'";
$query = mysql_query($sql);
if(!$query)
{
die(mysql_error());
}
if(mysql_num_rows($query) != 0)
{
$row=mysql_fetch_array($query);
$password=$row["password"];
$email=$row["email"];
$subject="your password";
$header="from:you@yourdomain.com";
$content="your password is ".$password;
mail($email, $subject, $content, $header);
print "An email containing the password has been sent to you";
}
else
{
echo("no such login in the system. please try again.");
}
}
?>
Any help or feedback would be greatly appreciated.
This post has been edited by macosxnerd101: 03 September 2012 - 10:26 AM
Reason for edit:: Please use code tags

New Topic/Question
Reply



MultiQuote








|