Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once('includes/fonction.php');
- if(isset($_POST['email_mdp'])){
- $characts = 'abcdefghijklmnopqrstuvwxyz';
- $characts .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $characts .= '1234567890';
- $code_aleatoire = '';
- for($i=0;$i < 6;$i++) //10 est le nombre de caractères
- {
- $code_aleatoire .= substr($characts,rand()%(strlen($characts)),1);
- }
- $reponse = $bdd->query('SELECT * FROM users WHERE email = \''.$_POST['email_mdp'].'\' ') or die(mysql_error());
- $donnees = $reponse->fetch();
- $req = $bdd->prepare('UPDATE users SET password = ? WHERE email = ?');
- $req->execute(array(md5($code_aleatoire), $_POST['email_mdp']));
- require 'includes/phpmailer/PHPMailerAutoload.php';
- $mail = new PHPMailer;
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail -> Host = 'smtp.gmail.com';
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'kaerizakifansub@gmail.com'; // SMTP username
- $mail->Password = 'XXXXXXXXX'; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
- $mail->Port = 587; //Set the SMTP port number - 587 for authenticated TLS
- $mail->setFrom('kaerizakifansub@gmail.com', 'Kaerizaki Fansub'); //Set who the message is to be sent from
- $mail->AddAddress($_POST['email_mdp']);
- $mail->isHTML(false); // Set email format to HTML
- $mail->Subject = ''.$config_site_nom.' - Mot de passe oublie';
- $mail->Body = 'Bonjour '.$donnees['pseudo'].', votre nouveau mot de passe est : '.$code_aleatoire.'';
- $mail->AltBody = 'Bonjour '.$donnees['pseudo'].', votre nouveau mot de passe est : '.$code_aleatoire.'';
- if(!$mail->send()) {
- echo 'Message could not be sent.';
- echo 'Mailer Error: ' . $mail->ErrorInfo;
- exit;
- }
- header('location:connexion.php?new_mdp');
- }else{
- header('location:connexion.php?mail-nok');
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement