duandongji2231 2016-03-04 03:47
浏览 28

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

I followed a password retrieval in codeigniter Password retrieval

But I am stucked in receiving my email. There's no error when displaying a 'send_reset_password_email' where I thought I already received it.

Controller:

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')));
}
}
}

Model:

   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;
    }
}

View: (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:(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:(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:(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

I have other questions regarding what this would be and how would I set this up:
$this->config->item('salt')
$this->config->item('bot_email')

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起