It is now working and changing the password but problem is I don't receive the email!!
I can't understand why, the email address I am using is set up on my mail system. I have emailed my host and they state;
"This issue is occuring because there is a missing fifth parameter in your mail script. This has always been a requirement of mail scripts on our shared hosting platform but recent updates to our Linux servers (from PHP4 to PHP5) has meant that this is now always required."
Any ideas what I can do to this code to solve the problem?
<?php
session_start();
include("data/data.php");
$conn = mysql_connect($servername, $user, $password) or die("Could not connect: " . mysql_error());
mysql_select_db($user, $conn);
// This is displayed if all the fields are not filled in
$empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>Click <a class=\"two\" href=\"javascript:history.go(-1)\">here</a> to go back";
// Convert to simple variables
$email = $_POST['email'];
if (!isset($_POST['email'])) {
?>
<h2>Recover a forgotten password!</h2>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<p class="style3"><label for="email">Email:</label>
<input type="text" title="Please enter your email address" name="email" size="30"/></p> <p class="style3"><label title="Reset Password"> </label>
<input type="submit" value="Submit" class="submit-button"/></p></form>
<?php
}
elseif (empty($email)) {
echo $empty_fields_message;
}
else {
$email=mysql_real_escape_string($email);
$status = "OK";
$msg="";
//error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
if (!stristr($email,"@") OR !stristr($email,".")) {
$msg="Your email address is not correct<BR>";
$status= "NOTOK";}
echo "<br><br>";
if($status=="OK"){ $query="SELECT name, email FROM sign_up WHERE users.email = '$email'";
$st=mysql_query($query);
$recs=mysql_num_rows($st);
$row=mysql_fetch_object($st);
$em=$row->email;// email is stored to a variable
if ($recs == 0) { echo "<center><font face='Verdana' size='2' color=red><b>No Password</b><br> Sorry Your address is not there in our database . You can signup and login to use our site. <BR><BR><a href='http://www.jackgodfrey.org.uk/register'>Register</a> </center>"; exit;}
function makeRandomPassword() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$random_password = makeRandomPassword();
$db_password = md5($random_password);
$sql = mysql_query("UPDATE sign_up SET password='$db_password' WHERE email='$email'");
$subject = "Your password at www.yoursite.com";
$message = "Hi, we have reset your password.
New Password: $random_password
http://www.yoursite.com/login
Once logged in you can change your password
Thanks!
Site admin
This is an automated response, please do not reply!";
mail($email, $subject, $message, "From: yoursite.com Webmaster<info@.co.uk>\n X-Mailer: PHP/" . phpversion());
echo "Your password has been sent! Please check your email!<br />";
echo "<br><br>Click <a href='http://www.yoursite.com/login'>here</a> to login";
}
else {echo "<center><font face='Verdana' size='2' color=red >$msg <br><br><input type='button' value='Retry' onClick='history.go(-1)'></center></font>";}
}
?>