<?php
$dt=password_forgot($_POST);
echo json_encode($dt);

function password_forgot($js){
  global $ar,$db;
  $dt=array();
  $dt['param']=$js;
  
  $email2 =$js['email'];  
  $em=explode('@',$email2);
  $m1 = preg_replace("/[^A-Za-z0-9]/","",$em[0]);
  
  if($m1!='' && $em[1]!='') {
    $email=$m1."@".$em[1];
    //cek email dobel
    $sql9="SELECT * from `member` where st=1 and email='".$email."'";
    //$dt['sql'][0]=$sql9;
    
    $res9=mysqli_query($db,$sql9);
    if(mysqli_num_rows($res9)==0) {
      $dt['status']=false;
      $dt['message']="Email '".$email."' tidak terdaftar";    
      //$dt['info'][0]="Email '".$email."' belum terdaftar";    
    } else {
      //$dt['message']="Email '".$email."' belum terdaftar";    
      //cek username
      if(mysqli_num_rows($res9)==1) {

        //$dt['info'][1]="Email '".$email."' terdaftar"; 
        $npass=genCode(8);   
        $r9=mysqli_fetch_assoc($res9);

        $sql8="UPDATE `member` set password='".$npass."' where `email`='".$email."'";
        //$dt['sql'][1]=$sql8;
        $res8=mysqli_query($db,$sql8);

        include "inc.mail.php";

        $subject="New password to login ".$ar['mail_name'].": ".$npass;
        $content= "<p>Welcome to ".$ar['mail_name']."</p>";
        $content.= "<p>your password to login is: ".$npass."</p>";
        $content.= "<p><br><br></p>";
        $content.= "<p>Best Regards,<br>".$ar['mail_name']." Team</p>";
        //$dt['m']['to']=$name;
        //$dt['m']['email']=$email;
        //$dt['m']['sub']=$subject;
        $cek_mail=sendMail($email,$r9['fullname'],$subject,$content);
        $dt['mail_success']=$cek_mail;
        $dt['status']=true;
        $dt['message']="Password sukses diperbarui silakan cek '".$email."'";    
        //$dt['data']=$r8;
        //$dt['data']['uuid']=$r8['id'];
      }
    }
  }
  
  return $dt;
  $db->close();
}
?>
/home/u1731472/public_html/
sub/cpapp_ekbis/api/v2/php/password_forgot.php