在我的控制器中,一个Login.php:
/* * *RESET AND SEND PASSWORD TO REQUESTED EMAIL*** */
function reset_password() {
$account_type = $this->input->post('account_type');
if ($account_type == "") {
redirect(base_url(), 'refresh');
}
$email = $this->input->post('email');
$result = $this->email_model->password_reset_email($account_type, $email); //SEND EMAIL ACCOUNT OPENING EMAIL
if ($result == true) {
$this->session->set_flashdata('flash_message', get_phrase('password_sent'));
} else if ($result == false) {
$this->session->set_flashdata('flash_message', get_phrase('account_not_found'));
}
redirect(base_url(), 'refresh');
}
在我的Email_model.php中:
function account_opening_email($account_type = '', $email = '')
{
$system_name = $this->db->get_where('settings', array('type' => 'system_name'))->row()->description;
$email_msg = "Welcome to " . $system_name . "<br />";
$email_msg .= "Your account type : " . $account_type . "<br />";
$email_msg .= "Your login password : " . $this->db->get_where($account_type, array('email' => $email))->row()->password . "<br />";
$email_msg .= "Login Here : " . base_url() . "<br />";
$email_sub = "Account opening email";
$email_to = $email;
$this->do_email($email_msg, $email_sub, $email_to);
}
function password_reset_email($account_type = '', $email = '') {
$query = $this->db->get_where($account_type, array('email' => $email));
if ($query->num_rows() > 0) {
$password = $query->row()->password;
$email_msg = "Your account type is : " . $account_type . "<br />";
$email_msg .= "Your password is : " . $password . "<br />";
$email_sub = "Password reset request";
$email_to = $email;
$this->do_email($email_msg, $email_sub, $email_to);
return true;
} else {
return false;
}
}
/* * *custom email sender*** */
function do_email($msg = NULL, $sub = NULL, $to = NULL, $from = NULL) {
$config = array();
$config['useragent'] = "CodeIgniter";
$config['mailpath'] = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol'] = "smtp";
$config['smtp_host'] = "localhost";
$config['smtp_port'] = "25";
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$this->load->library('email');
$this->email->initialize($config);
$system_name = $this->db->get_where('settings', array('type' => 'system_name'))->row()->description;
if ($from == NULL)
$from = $this->db->get_where('settings', array('type' => 'system_email'))->row()->description;
$this->email->from($from, $system_name);
$this->email->from($from, $system_name);
$this->email->to($to);
$this->email->subject($sub);
$msg = $msg . "<br /><br /><br /><br /><br /><br /><br /><hr /><center><a>© 2017 blablabla</a></center>";
$this->email->message($msg);
$this->email->send();
//echo $this->email->print_debugger();
}
}
在View中,一个login.php:
仅重置部分
<!-----------password reset form ------>
<div class="modal fade" id="modal_ajax">
<div class="modal-dialog" >
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><?php echo get_phrase('reset_password');?></h4>
</div>
<div class="modal-body" style="height:100px; overflow:auto;">
<div class="modal-body">
<?php echo form_open('Login/reset_password');?>
<div class="col-sm-5">
<select class="form-control" name="account_type" style="margin-bottom: 0px !important;">
<option value=""><?php echo get_phrase('account_type');?></option>
<option value="doctor"><?php echo get_phrase('doctor');?></option>
<option value="patient"><?php echo get_phrase('patient');?></option>
<option value="nurse"><?php echo get_phrase('nurse');?></option>
<option value="pharmacist"><?php echo get_phrase('pharmacist');?></option>
<option value="laboratorist"><?php echo get_phrase('laboratorist');?></option>
<option value="receptionist"><?php echo get_phrase('receptionist');?></option>
</select>
</div>
<div class="col-sm-5">
<input type="email" name="email" class="form-control" id="field-1" placeholder="Enter Email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" title="Please enter a valid email" >
</div>
<input type="submit" value="<?php echo get_phrase('reset');?>" class="btn btn-blue btn-medium"/>
<?php echo form_close();?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
我无法弄明白为什么它不起作用,它只是刷新页面。 Plzz帮我解决了这个问题