slave ragazzi sto diventando matto a capire perchè questo code non funziona l'utente quando inserisce la email nel form per resettare la password non succede nulla
Codice:
Form
----------------------------
head>
<title>Forgot password in php</title>
<link href="style.css" type="text/css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<script src="script.js"></script>
<div class="container">
<div class="err"></div>
<form id="mobile-number-verification">
<div class="mobile-heading">Forgot password</div>
<div class="mobile-row">
<input type="email" id="email" class="mobile-input" placeholder="Enter your email-id">
<div id="message2"></div>
</div>
<div id="loading-image"><img src="ajax-loader.gif" alt="ajax loader"></div>
<input type="button" class="mobileSubmit" id="enter" disabled="true" value="Send password reset link" onClick="generateUrl();">
</form>
</div>
<script>
$('#email').on('keyup',function(){
var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var mailformat = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
var email = $("#email").val();
if(email.match(mailformat)){
$('#message2').html('valid').css('color','green');
$("#enter").prop('disabled',false);
}
else
$('#message2').html('Invalid Email').css('color','red');
}
);
</script>
</body>
</html>
------------------------ script js
function generateUrl() {
$(".err").html("").hide();
var email = $("#email").val();
var name = $("#name").val();
if(name.length !== 0)
{
var input ={
"name" : name,
"email" : email,
"action" : "generate_url"
}
$("#loading-image").show();
$.ajax({
url : 'controller.php',
type : 'POST',
dataType : 'json',
data : input,
success : function(response)
{
$(".container").html(response.message);
},
complete : function()
{
$("#loading-image").hide();
},
error : function()
{
$(".container").html("Error");
}
});
}
else
$("#message1").html("Enter your name").css('color','red');
}
------------------------------
invio mail
<?php
error_reporting(E_ALL & ~ E_NOTICE);
switch ($_POST["action"]) {
case "generate_url":
$email = $_POST['email'];
$name = "User";
$token = sha1(uniqid($email,true)); // this will generate unique 40 character long secured token
$db = mysqli_connect('localhost', '**********', '**********', '************');
//here check for email id ia already registered or not
$query=mysqli_query($db,"INSERT INTO forgot-password-request (name,email,token) VALUES ('$name','$email','$token')");
$result = mysqli_query($db, $query);
if ($result === FALSE)
{
die(mysqli_error());
exit();
}
else{
$url = "http://amministrazione.netsons.org/user-verification.php?token=$token";// send this url to user via email
$message = "Segui questo collegamento " . $url . " per reimpostare la password dimenticata.";
$sub = "Attiva il tuo account sul sito Amministrazione";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: Amministrazione <[email protected]>' . "\r\n";
$retval = mail($email,$sub,$message,$headers);
if($retval = true)
echo json_encode(array( "type" =>"success", "message" => "Password link has been sent to email id"));
else
echo json_encode(array( "type" =>"error", "message" => "Error sending mail."));
}
break;
}
?>