我创建了一个密码重置功能,当用户输入他的id时它会工作,然后将id插入到查询中以查找用户的密码。找到密码后,密码将被发送到用户邮箱。 从用户ID获取的电子邮件。但我的功能不起作用,我没有收到任何错误信息,所以我不知道我的代码有什么问题。
- 这是我的观点 -
<!-- Modal Body -->
<div class="modal-body">
<p class="statusMsg"></p>
<form role="form" id="formPass" action='<?php echo base_url() ?>kirim_form' method="post">
<div class="form-group">
<label for="masukkanNpk">Masukkan NPK:</label>
<input type="text" class="form-control" id="npk" placeholder="Masukkan NPK Anda"/>
</div>
</form>
</div>
<!-- Modal Footer -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Tutup</button>
<button type="button" class="btn btn-primary submitBtn" onclick="kirimContactForm()">KIRIM</button>
</div>
- 用户提交ID后,这是我的功能 -
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
Forgotpassword email sender:
No view
*/
class Kirim_form extends Xcentrix_Controller
{
public function ForgotPass()
{
$email = $this->input->post('npk');
$findemail = $this->db->query("select email from cc_customer where npk = '".$email."'");
if($findemail){
$this->usermodel->sendpassword($findemail);
}else{
// $this->session->set_flashdata('msg',' Email not found!');
echo "Email not found!";
redirect(base_url().'/','refresh');
}
}
//funtion to get email of user to send password
public function ForgotPassword($email)
{
$this->db->select('email');
$this->db->from('cc_customer');
$this->db->where('npk', $email);
$query=$this->db->get();
return $query->row_array();
}
public function sendpassword($findemail)
{
$email = $findemail['email'];
$query1=$this->db->query("SELECT * from cc_customer a,cc_user b where a.npk = b.npk and a.email = '".$email."' ");
$row=$query1->result_array();
if ($query1->num_rows()>0)
{
$yourPass = md5($row->password);
$this->db->where('email', $email);
$mail_message='Dear '.$row[0]['customer_name'].','. "\r\n";
$mail_message.='<br>Lupa Password ITCare Berhasil!';
$mail_message.='Password ITCare atas NPK '.$row->npk.'('.$row->customer_name.') adalah <b>'.$yourPass.'</b>'."\r\n";
$mail_message.='<br>Terima Kasih';
$mail_message.='<br>ITCare System';
date_default_timezone_set('UTC+7');
require FCPATH.'assets/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPSecure = "tls";
$mail->Debugoutput = 'html';
$mail->Host = "172.16.5.20";
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = "helpdesk@acc.co.id";
$mail->setFrom('helpdesk@acc.co.id', 'Rizki');
$mail->IsHTML(true);
$mail->addAddress('dpalevi@gmail.com');
// $mail->addAddress($email);
$mail->Subject = '[ITCARE] Konfirmasi Password';
$mail->Body = $mail_message;
$mail->AltBody = $mail_message;
if (!$mail->send()) {
// $this->session->set_flashdata('msg','Failed to send password, please try again!');
echo "Failed to send password, please try again!";
} else {
// $this->session->set_flashdata('msg','Password sent to your email!');
echo "Password sent to your email!";
$status = 'ok';
}
redirect(base_url().'/','refresh');
}
else
{
// $this->session->set_flashdata('msg','Email not found try again!');
echo "Email not found try again!";
redirect(base_url().'/','refresh');
}
}
}
?>
- 这是一些javascript -
function kirimContactForm(){
var reg = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
var npk = $('#npk').val();
// var email = $().val();
if(npk.trim() == '' ){
alert('Masukkan NPK Anda.');
$('#npk').focus();
return false;
}else{
$.ajax({
type:'POST',
url:$('#formPass').attr('action'),
data:'contactFrmSubmit=1&npk='+npk,
beforeSend: function () {
$('.submitBtn').attr("disabled","disabled");
$('.modal-body').css('opacity', '.5');
},
success:function(msg){
if(msg == 'ok'){
$('#masukkanNpk').val('');
$('.statusMsg').html('<span style="color:green;">Password akan dikirimkan ke email:' , '<br><br> Jika tidak menerima email harap menghubungi helpdesk di <u>021-75998699</u></p>');
}
else{
$('.statusMsg').html('<span style="color:red;">Mohon Maaf email anda tidak ada di sistem ITCare. Password akan dikirim ke atasan anda di:', '<br><br>Jika tidak menerima email harap menghubungi helpdesk di <u>021-75998699</u> </span>');
}
$('.submitBtn').removeAttr("disabled");
$('.modal-body').css('opacity', '');
}
});
}
}
感谢提前