query('SELECT COUNT(*) FROM UTILISATEUR WHERE mail="'.$mail.'"');
$row = $existe->fetchAll(PDO::FETCH_COLUMN, 0);
$res=intval($row[0]);
var_dump($mail);
var_dump($res);
function genererChaineAleatoire($longueur = 14)
{
$caracteres = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$longueurMax = strlen($caracteres);
$chaineAleatoire = '';
for ($i = 0; $i < $longueur; $i++)
{
$chaineAleatoire .= $caracteres[rand(0, $longueurMax - 1)];
}
return $chaineAleatoire;
}
if($res==1){
function smtpMailer($code) {
$email=$_POST['mail'];
$mail = new PHPMailer(TRUE);
try {
//Server settings
$mail->SMTPDebug = 0;//Enable verbose debug output
$mail->isSMTP();//Send using SMTP
$mail->Host = 'smtp.gmail.com';//Set the SMTP server to send through
$mail->SMTPAuth = true;//Enable SMTP authentication
$mail->Username = 'basketprojet4@gmail.com';//SMTP username
$mail->Password = 'jesuismdp4';//SMTP password
$mail->SMTPSecure = 'tls';//Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587;//TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('no-reply@basket.com', 'Basket Team');
$mail->addAddress($email);
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Nouveau mot de passe';
$mail->Body = 'Voici votre nouveau mot de passe, celui ci sera temporaire jusqu\'à votre prochaine connexion '.$code.'';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
$code = genererChaineAleatoire();
$result = smtpmailer($code);
if (true !== $result)
{
$statement = $db->query('UPDATE UTILISATEUR SET motDePasse = "'.$code.'", mdpOublie=1 WHERE mail = "'.$mail.'"');
$row = $statement->fetchAll(PDO::FETCH_COLUMN, 0);
$res=intval($row[0]);
header('Location: vueConnexion.php');
exit();
}
}else{
header('Location: renvoiMotDePasse.php');
exit();
}
$db=null;
} catch(PDOException $e)
{
}
}
?>