View Single Post
Old 10-05-2012, 02:13 PM   PM User | #33
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 860
Thanks: 68
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
Ok so I have wrote the email and it sent successfully on 2 occasions but I tried doing it several times since and it isn't sending me the email now.

Here is my reset pass action script:
PHP Code:
<?php

if(isset($_POST['username'])){

   
$errors = array();
   
$_POST['username'] = trim($_POST['username']);
   
   if(empty(
$_POST['username'])){
      
$errors[] = "You must fill in the username field.";
   }
   
     if(empty(
$errors)){
        
//code checks whether the username matches one in the database, if it does, we create a unique key and update that users reset field.
        
$con = new mysqli("sql110.0fees.net","fees0_11240271","h4ck3r","fees0_11240271_demo_central");
        
$stmt $con->prepare("SELECT * FROM members WHERE username=?");
        
        
$username mysqli_real_escape_string($con,$_POST['username']);
        
        
$stmt->bind_param("s",$username);
        
$stmt->bind_result($id,$user,$pass,$email,$join_date,$hash,$reset);
        
$stmt->execute();
        
$stmt->store_result();
        
$row $stmt->num_rows;
        
$stmt->fetch();
        
        
        if(
$row == 1){//if $row == 1, we matched a correct username from the database....so we create a unique id to insert into users row.
           
           
$unique_id uniqid();
           
           
$stmt $con->prepare("UPDATE members SET reset=? WHERE username=?");
           
$stmt->bind_param("ss",$unique_id,$user);
           
$stmt->execute();
           
$stmt->store_result();
           
$a_row $stmt->affected_rows;
           
           if(
$a_row == 1){
              
              
//if this executes, database was updated with reset code. write email...
              
$to $email;
              
$subject "Demo-Central Reset Password."."\r\n";
              
$message "Hello ".$user."<br />\r\n";
              
$message .= "You have received this email because you have forgotten your password."."<br />\r\n";
              
$message .= "We have attached a link within the email which needs to be clicked in order to process"."<br />\r\n";
              
$message .= "your password reset. On this page you will be asked to enter your new password. Once you have done this"."<br />\r\n";
              
$message .= "you will then be able to login with your existing username and new password."."<br /><br />\r\n";
              
$message .= "<a href='htttp://www.labtec.0fees.net/DemorecSite/enter_new_pass.php?id={$id}&unique={$unique_id}'>Reset your password!</a><br /><br />";
              
$message .= "Kind regards,"."<br />\r\n";
              
$message .= "Demo-Central Administrator."."<br />\r\n";
              
              
$headers = array();
              
$headers[] = "MIME-Version: 1.0";
              
$headers[] = "Content-type: text/html; charset=iso-8859-1";
              
$headers[] = "From: Demo-Central Admin <admin@demo-central.com>";
              
$headers[] = "Bcc: JJ Chong <bcc@domain2.com>";
              
$headers[] = "Reply-To: Recipient Name <receiver@domain3.com>";
              
$headers[] = "Subject: {$message}";
              
$headers[] = "X-Mailer: PHP/".phpversion();
      
              if(
mail($to,$subject,$messageimplode("\r\n",$headers))){
                 echo 
"You will be emailed shortly with further instructions on resetting your password.<br />";
                 echo 
"Please follow the <a href='index.php'>link</a> to the homepage.";
                 exit(
0);
              }
              else{
                 echo 
"There was an error sending your reset email.<br />";
                 echo 
"Please contact the site administrator at flipmodeskwaud@hotmail.co.uk to report the problem.<br />";
                 echo 
"Follow the link to the <a href='index.php'>homepage</a>.";
                 exit(
0);
              }
              
           }
           else{
           
//print error
           
}
           
           
        }
        else{
           print(
"That username does not exist.<br />");
           print(
"<a href='reset_password.php'>Please try again.</a>");
           exit(
0);
        }
        
     }
     else{
        
$error_string implode("<br />",$errors);
        print(
$error_string);
        print(
"<br />");
        print(
"<a href='reset_password.php'>Please try again.</a>");
        exit(
0);
     }
}

?>
Do you know what the issue could be?

Kind regards,

LC.
__________________
Carewizard - http://www.carewizard.co.uk
LearningCoder is offline   Reply With Quote