Php 如何使用MVC方法通过电子邮件重置密码?
在我的控制器中,一个Login.php:Php 如何使用MVC方法通过电子邮件重置密码?,php,codeigniter,email,Php,Codeigniter,Email,在我的控制器中,一个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'); }
/* * *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');
}
在我的电子邮件_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();
}
}
function account\u opening\u email($account\u type='',$email='')
{
$system\u name=$this->db->get\u where('settings',array('type'=>'system\u name'))->row()->description;
$email\u msg=“欢迎使用“$system\u name”。
;
$email_msg.=“您的帐户类型:”.$account_type.“
”;
$email\u msg.=“您的登录密码:”.this->db->get\u where($account\u type,array('email'=>$email))->row()->password。”
;
$email_msg.=“在此处登录:”.base_url()。“
”;
$email\u sub=“开户电子邮件”;
$email_to=$email;
$this->do\u email($email\u msg、$email\u sub、$email\u to);
}
函数密码\u重置\u电子邮件($account\u type='',$email=''){
$query=$this->db->get_-where($account_-type,数组('email'=>$email));
如果($query->num\u rows()>0){
$password=$query->row()->password;
$email_msg=“您的帐户类型为:“..$account_type.”
”;
$email_msg.=“您的密码是:”..$password.“
”;
$email\u sub=“密码重置请求”;
$email_to=$email;
$this->do\u email($email\u msg、$email\u sub、$email\u to);
返回true;
}否则{
返回false;
}
}
/***自定义电子邮件发件人****/
函数do_email($msg=NULL,$sub=NULL,$to=NULL,$from=NULL){
$config=array();
$config['useragent']=“CodeIgniter”;
$config['mailpath']=“/usr/bin/sendmail”;//或“/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\u name=$this->db->get\u where('settings',array('type'=>'system\u name'))->row()->description;
if($from==NULL)
$from=$this->db->get_where('settings',array('type'=>'system_email'))->row()->description;
$this->email->from($from,$system\u name);
$this->email->from($from,$system\u name);
$this->email->to$to;
$this->email->subject($sub);
$msg=$msg.“
©;2017 blablabla”;
$this->email->message($msg);
$this->email->send();
//echo$this->email->print_debugger();
}
}
在视图中,一个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');
}
仅重置部件
<!-----------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>
&时代;
您的日志中出现了什么错误?空页表示您从PHP中得到了服务器错误。日志中有什么?运行phpinfo();点击control+F并搜索错误日志。看看那个档案里面。你必须学会如何使用你的工具。如果一个木匠抱怨钉子没钉进木头,不愿意在地上捡起锤子,没有人会把他当回事