How to send forgot password email in jquery? I have the same code i n php? can any one help me write a jquery code for the same.

How to send forgot password email in jquery? I have the same code i n php? can any one help me write a jquery code for the same.

 <!--AJAX CALLS THIS CODE TO EXECUTE  -->
    <script>
        if(isset($_Post["e"])){
            $sql = "SELECT id, username FROM users WHERE email ='$e' And activated='1' LIMIT 1";
            $query = mysqli_query($db_conx, $sql);
            $numrows = mysqli_num_rows($query);
            if($numrows >0){
                while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
                    $id = $row["id"];
                    $u = $row["username"];
                }
                $emailCut = substr($e,0,4);
                $randNum = rand(10000, 99999);
                $tempPass = "$emailCut$randNum";
                $hashTempPass = md5($tempPass);
                $sql = "UPDATE userOptions SET temp_pass='$hashTempPass' where username='$u' LIMIT 1";
                $query = mysqli_query($db_conx , $sql);
                $to = "$e";
                $from = "auto_responder@iicorporate.com";
                $headers = "From : $from\n";
                $headers ="MIME-Version : 1.0\n";
                $headers ="Content-type : text/html; charset=iso8859-1\n";
                $subject = "IICorporate Temporary Password";
                $msg = '<h2> Hello'.$u.'</h2><p>This is an automated message from IICorporate. If you did not recently initiate the Forgot Password process, please disregard this email.</p><p> You indicated that you forgot your login password. We can generate a temporary password for you to log in with, then once logged in you can change your password to anything you like.</p><p> After you click the link below your password will be :<br /><b>'.$tempPass.'</b></p><p><a href="http://localhost:1337/flow/client/app/login.htm?u='.$u.'&p='.$hashTempPass.'">Click here now to apply the temporary password shown below to your account</a></p><p> If you do not click the link in this email, no changes will be made to your order to set your login password to the temporary password , you must click the link above. </p>';
                if(mail($to,$subject,$msg,$headers)){
                    document.write("success");
                    exit();
                }else{
                    document.write("email_send_failed");
                    exit();
                }
            }else{
                document.write("no_exist");
            }

            exit();

        }
    </script>

    <!--EMAIL LINK CLICK CALLS THIS CODE TO EXECUTE  -->
    <script>
        if(isset($GET['u']) && isset($_GET['p'])){
            $u = preg_replace('#[^a-z0-9]#i', '', $GET['p']);
        $tempPassHash = preg_replace('#[^a-z0-9]#i', '', $_GET['p']);
        if(strlen($tempPassHash) < 10){
            exit();
        }
        $sql = "SELECT id FROM userOptions WHERE username='$u' AND temp_pass = '$tempPassHash' LIMIT 1";
        $query = mysqli_query($db_conx , $sql);
        $numrows = mysqli_num_rows($query);
        if($numrows == 0){
            header("location : message.js?msg=There is no match for that username with that temporary password in the system");
            exit();
        } else{
            $row = mysqli_fetch_row($query);
            $id = $row [0];
            $sql = "UPDATE users SET password='$tempPassHash' WHERE id='$id' AND username='$u' LIMIT 1";
            $query = mysqli_query($dbconx, $sql);
            $sql = "UPDATE userOptions SET temp_pass='' WHERE username='$u' LIMIT 1";
            $query = mysqli_query($dbconx,$sql);
            header("location :login.htm");
            exit();
        }
        }




    </script>




</head>

<script>
    function forgotPass(){
        var e= ("email").value;
        if(e == ""){
            ("status").innerHTML = "Type in your email address";
        }else{
            ("forgotPassBtn").style.display = "none";
            ("status").innerHTML = 'please wait...';

            var ajax= ajaxObj("POST","forgotPass.htm");
            ajax.onReadyStateChange = function (){
                if(ajaxReturn(ajax) == true) {
                    var response = ajax.responseText;
                    if(response == "success"){
                        ("forgotPassForm").innerHTML = '<h3>Step 2. Check your email inbox in a few minutes</h3> <p>You can close this window if you like</p>';
                    }else if(response == "no exist"){
                        ("status").innerHTML = "Sorry that email address is not in our system";
                    }else if(response == "email_send_failed"){
                        ("status").innerHTML = "Mail function failed to execute";
                    }else{
                        ("status").innerHTML = "An unknown error occurred.";
                    }
                }
            }
            ajax.send("e=" +e);
        }
    }



</script>




<form id='forgotPassForm' onsubmit="return false;">
    <div id='divMain'>
        <div id='divLoginHdr'>
            <label> Generate Temporary Log in Password</label>
        </div>
        <div id='divCenterSection'>
            <div> Step 1: Enter your Email Address </div>
            <input type='text' name='forgotPass' id='email' onfocus="('status').innerHTML='';"  placeholder='email' size='45'/>
            <br/> <br/>
    <button id="forgotPassBtn" onClick="forgotPass()">Submit</button>
            <br>
            <p id="status"> </p>
            <br/>
            <br/>
            <br/>
            <br/>
            <br/>
            </div>
    </div>
</form>
</html>