密码检索系统不发送电子邮件codeigniter

时间:2016-03-04 03:47:57

标签: php codeigniter localhost forgot-password

我在codeigniter中进行了密码检索 Password retrieval

但是我很难接收我的电子邮件。显示“send_reset_password_email”时没有错误,我认为我已收到它。

控制器:

public function reset_password(){

  if(isset($_POST['email'])  && !empty($_POST['email'])){
     $this->load->library('form_validation');
     $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');

             if ($this->form_validation->run() == FALSE){
                $this->load->view('member/retrievepassword', array('error'=> 'Please supply a valid email address'));
}else{
    $email= trim($this->input->post('email'));
    $result= $this->MemberLoginModel->email_exists($email);

    if($result){
        $this->send_reset_password_email($email, $result);
        $this->load->view('member/view_reset_password_sent',
            array('email'=> $email));
    }else{
             $this->load->view('member/retrievepassword', 
            array('error'=>'Email address not registered with Findining'));    
    }
}
}else{
 $this->load->view('member/retrievepassword');
}
}

private function send_reset_password_email($email, $memberfname){

 //load email library
$this->load->library('email');
$email_code = md5($this->config->item('salt').$memberfname);

$this->email->set_mailtype('html');
$this->email->from($this->config->item('bot_email'), 'Findining');
$this->email->subject('Please reset your password at Findining');

$message = '<!DOCTYPE html PUBLIC ".//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html>
            <meta http-equiv="Content-Type" content="text/html; charset-utf-8" />
            </head><body>';
$message .='<p>Dear '.$memberfname.',</p>';
$message .='<p>We want to help you reset your password! 
            Please <strong><a href ="'.base_url().'MemberLoginController/reset_password_form/'.$email.'/'.
            $email_code.'">click here</a></strong> to reset your password.</p>';
$message .='<p>Thank you!</p>';
$message .='<p>The Team at Findining Cebu City</p>';
$message .='</body></html>';

$this->email->message($message);
$this->email->send();

}

public function reset_password_form($email, $email_code){

  if(isset($email, $email_code)){
    $email=trim($email);
    $email_hash= sha1($email . $email_code);
    $verified = $this->MemberLoginModel->verify_reset_password_code($email, $email_code);

    if($verified){
        $this->load->view('member/view_update_password', 
            array('email_hash'=> $email_hash,
                  'email_code'=> $email_code,
                  'email'=> $email
                ));
    }else{
        $this->load->view('member/retrievepassword',array('error'=>'There was a problem with your link.
            Please click it again or request to reset your password again', 'email'=> $email));
    }
  }   
}

public function update_password(){
if(!isset($_POST['email'], $_POST['email_hash']) || $_POST['email_hash'] !== sha1($_POST['email'].$_POST['email_code'])){
    die('Error updating your password');
}

$this->load->library('form_validation');

$this->form_validation->set_rules('email_hash', 'Email Hash', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('new_pw','New Password','required|max_length[20]|min_length[4]|trim');
$this->form_validation->set_rules('conf_pw','Confirm Password','required|matches[new_pw]');

if($this->form_validation->run()==FALSE){
    $this->load->view('member/view_update_password');
}else{
    $result=$this->MemberLoginModel->update_password();

    if($result){
        $this->load->view('member/view_update_password_success');
    }else{
        $this->load->view('member/view_update_password', array('error'=>'Problem updating your password. 
            Please contact'.$this->config->item('admin_email')));
}
}
}

型号:

   public function email_exists($email){

    $sql="SELECT memberfname, email FROM member WHERE email='{$email}' LIMIT 1";
    $result= $this->db->query($sql);
    $row=$result->row();

    return($result->num_rows()===1 && $row->email) ? $row->memberfname : false;

}
    public function verify_reset_password_code($email, $code){
    $sql="SELECT memberfname, email FROM member WHERE email='{$email}' LIMIT 1";
    $result= $this->db->query($sql);
    $row = $result->row();

    if($result->num_rows()===1){
        return($code==md5($this->config->item('salt') . $row->memberfname)) ? true : false;
    }else{
        return false;
    }
}

    public function update_password(){
    $email=$this->input->post('email');
    $password=sha1($this->config->item('salt').$this->input->post('password'));

    $sql="UPDATE member SET password = '{$password}' WHERE email='{$email}' LIMIT 1";
    $this->db->query($sql);

    if($this->db->affected_rows()===1){
        return true;
    }else{
        return false;
    }
}

查看: (retrievepassword.php)

<form action='<?=base_url('forgotpass')?>' method="POST">
 <div class="wow fadeInLeft" data-wow-delay="0.4s">
<span>Email: </span><br><?php echo form_error('email'); ?>
<input style="width: 60%;" type="text" id="email" name="email" value="<?php echo set_value('email'); ?>" required /> 

</div>
<br>
 <div class="wow fadeInLeft" data-wow-delay="0.4s">
 <input type='submit' name='submit' value='Reset My Password' />
</div>
</form>

查看:(view_reset_password_sent.php)

<center>
  <?php 
  echo  '<h2>'.'A link to reset your password has been sent to '.$email.'</h2>';
  echo br();
?>
</center>

查看:(view_update_password)

<form action='<?=base_url('updatepass')?>' method="POST">
 <div class="wow fadeInLeft" data-wow-delay="0.4s">
<span>Email: </span><br>
<?php if (isset($email_hash,$email_code)) { ?>
<input type="hidden" value="<?php echo $email_hash?>" name="email_hash" />
<input type="hidden" value="<?php echo $email_code?>" name="email_code" />
<?php } ?>
<input type="email" value="<?php echo (isset($email)) ? $email : ''; ?>" name="email"/>
</div>
<br>

<div class="wow fadeInLeft" data-wow-delay="0.4s">
<span>New Password: </span><br>
<input type="password" value="" name="new_pw"/>
</div>
<br>
<div class="wow fadeInLeft" data-wow-delay="0.4s">
<span>Re-type New Password: </span><br>
<input type="password" value="" name="conf_pw"/>
</div>
<br>
 <div class="wow fadeInLeft" data-wow-delay="0.4s">
 <input type='submit' name='submit' value='Update My Password' />
</div>
</form>
<?php 
    echo validation_errors('<p class="error">');
?>

查看:(view_update_password_success.php)

 <?php 
 echo  'Your password has been updated! You may now login to this site.';
 ?> 

XAMPP / PHP / php.ini中

sendmail_path = "\"E:\xampp\sendmail\sendmail.exe\" -t"
;sendmail_path="E:\xampp\mailtodisk\mailtodisk.exe"

XAMPP / sendmail的/ sendmail.ini

smtp_port=587
smtp_ssl=auto
auth_username=mymail@gmail.com
auth_password=mypassword

关于这将是什么以及如何设置,我还有其他问题:
    $这 - &GT; config-&GT;项( '盐')
    $这 - &GT; config-&GT;项( 'bot_email')

0 个答案:

没有答案