I have this script which works fine, and changes the password.
Admin is logged in and has a session id.
After admin has changed the password, i want to email the new changed password, but it doesnt send the email - can someone see why?
The form inputs are:
current password....
new password....
confirm new password....
This is the script:
<?php //error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); ?>
<?php
$password ='';
// Validate current pass
// only checks if theres a value
if(!empty($_POST['bekræftpass'])){
$currentPass = sha1(mysqli_real_escape_string($connection, $_POST['bekræftpass']));
} else{ // Error msg.
$currentPassEmpty ='<br /><small class="error">Indtast en værdi i feltet!</small>';
}
// Validate new pass
if(
ctype_alnum($_POST['pass1']) // KUN tal og bogstaver
&& strlen($_POST['pass1'])>5 // Mindst 6 karakterer lang
&& strlen($_POST['pass1'])<21 // Højst 20 karakterer lang
&& preg_match('`[A-Z]`',$_POST['pass1']) // Indeholder mindst et stort bogstav
&& preg_match('`[a-z]`',$_POST['pass1']) // Indeholder mindst et lille bogstav
&& preg_match('`[0-9]`',$_POST['pass1']) // Indeholder mindst et tal
){
// Valid!!
$new_password = mysqli_real_escape_string($connection, $_POST['pass1']);
$ValidPassword = '<br /><small class="error">Password er gyldigt!</small>';
}else{
// Not Valid!!
$InvalidPassword = '<br /><small class="error">Ugyldigt Password</small>';
}
// Checks if the two pass are alike
if($_POST['pass1']!=$_POST['pass2']){
$passwordDoesntMatch = '<br /><small class="error">De to password er ikke ens!</small>';
} else {
if($_POST['pass1']==$_POST['pass2']){
$password = sha1(mysqli_real_escape_string($connection, $_POST['pass1']));
}
// Validation done! *******************************
// Check if user or pass exists in DB
if(empty($currentPassEmpty) &&
empty($InvalidPassword) &&
empty($passwordDoesntMatch)){ // No errors..
$query = "SELECT id, email FROM users WHERE pass='$currentPass' AND id={$_SESSION['id']}";
$result = mysqli_query($connection, $query);
while($row=mysqli_fetch_array($result)){
$email = $row['email']; // The email that recieves the changed password
}
if(mysqli_num_rows($result)!=1){ // No users found!
$CurrentPassFindesIkke = 'Det indtastede password eksisterer ikke i systemet';
}
if(mysqli_num_rows($result)==1) { // 1 user, update and email the changed password
$updateQuery = "UPDATE users SET pass='$password' WHERE id={$_SESSION['id']} LIMIT 1";
if($result = mysqli_query($connection, $updateQuery)){
$PasswordChanged = '<br />Dit Password er blevet ændret og sendt til din email';
$to = $email; // The email adress from the above select - DOESNT GET SELECTED IT SEEMS?
$subject = "Dit ændrede password til admin!";
$message = 'Dit ændrede password til login er: <b>'.$new_password.'</b><br /><br />
Med Venlig Hilsen<br />
enkelt-webdesign.dk';
$headers = "Content-type: text/html\r\n";
$headers .= "<h3 style=\"color:#5581aa;\">Dit password er blevet ændret!</h3>";
$headers .= "<hr />";
mail($to,$subject,$message,$headers);
}
}
}
}
?>