Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <?php
  2. include_once('includes/fonction.php');
  3.  
  4. if(isset($_POST['email_mdp'])){
  5.  
  6.  
  7. $characts = 'abcdefghijklmnopqrstuvwxyz';
  8. $characts .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  9. $characts .= '1234567890';
  10. $code_aleatoire = '';
  11.  
  12. for($i=0;$i < 6;$i++) //10 est le nombre de caractères
  13. {
  14. $code_aleatoire .= substr($characts,rand()%(strlen($characts)),1);
  15. }
  16. $reponse = $bdd->query('SELECT * FROM users WHERE email = \''.$_POST['email_mdp'].'\' ') or die(mysql_error());
  17. $donnees = $reponse->fetch();
  18.  
  19. $req = $bdd->prepare('UPDATE users SET password = ? WHERE email = ?');
  20. $req->execute(array(md5($code_aleatoire), $_POST['email_mdp']));
  21.  
  22.  
  23.  
  24. require 'includes/phpmailer/PHPMailerAutoload.php';
  25. $mail = new PHPMailer;
  26. $mail->isSMTP(); // Set mailer to use SMTP
  27. $mail -> Host = 'smtp.gmail.com';
  28. $mail->SMTPAuth = true; // Enable SMTP authentication
  29. $mail->Username = 'kaerizakifansub@gmail.com'; // SMTP username
  30. $mail->Password = 'XXXXXXXXX'; // SMTP password
  31. $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
  32. $mail->Port = 587; //Set the SMTP port number - 587 for authenticated TLS
  33. $mail->setFrom('kaerizakifansub@gmail.com', 'Kaerizaki Fansub'); //Set who the message is to be sent from
  34. $mail->AddAddress($_POST['email_mdp']);
  35. $mail->isHTML(false); // Set email format to HTML
  36. $mail->Subject = ''.$config_site_nom.' - Mot de passe oublie';
  37. $mail->Body = 'Bonjour '.$donnees['pseudo'].', votre nouveau mot de passe est : '.$code_aleatoire.'';
  38. $mail->AltBody = 'Bonjour '.$donnees['pseudo'].', votre nouveau mot de passe est : '.$code_aleatoire.'';
  39.  
  40.  
  41. if(!$mail->send()) {
  42. echo 'Message could not be sent.';
  43. echo 'Mailer Error: ' . $mail->ErrorInfo;
  44. exit;
  45. }
  46. header('location:connexion.php?new_mdp');
  47. }else{
  48. header('location:connexion.php?mail-nok');
  49. }
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement