Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. if (isset($_POST["recovery_pass"]))
  2. {
  3. if (filter_var($_POST["email"], FILTER_VALIDATE_EMAIL))
  4. {
  5. $email = $_POST["email"];
  6. }
  7. else
  8. {
  9. echo "email is not valid";
  10. exit;
  11. }
  12.  
  13. // Check to see if a user exists with this e-mail
  14. $query = $conexao->prepare('SELECT email FROM users WHERE email = :email');
  15. $query->bindParam(':email', $email);
  16. $query->execute();
  17. $userExists = $query->fetch(PDO::FETCH_ASSOC);
  18. $conexao = null;
  19.  
  20. if ($userExists["email"])
  21. {
  22. // Create a unique salt. This will never leave PHP unencrypted.
  23. $salt = "498#2D83B631%3800EBD!801600D*7E3CC13";
  24.  
  25. // Create the unique user password reset key
  26. $password = hash('sha512', $salt.$userExists["email"]);
  27.  
  28. // Create a url which we will direct them to reset their password
  29. $pwrurl = "$linkSite/recovery_pass/$password";
  30.  
  31. require ("phpmailer/PHPMailerAutoload.php");
  32. // Inicia a classe PHPMailer
  33. $mail = new PHPMailer;
  34.  
  35. $mail->isSMTP(); // Set mailer to use SMTP
  36. $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
  37. $mail->SMTPAuth = true; // Enable SMTP authentication
  38. $mail->Username = 'curruwilla@gmail.com'; // SMTP username
  39. $mail->Password = '4586928wW#0'; // SMTP password
  40. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  41. $mail->Port = 587;
  42.  
  43. // Define o remetente
  44. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  45. $mail->setFrom = ('curruwilla@gmail.com'); // Seu e-mail
  46.  
  47. // Define os destinatário(s)
  48. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  49. $mail->AddAddress($email);
  50.  
  51. $mail->IsHTML(true); // Define que o e-mail será enviado como HTML
  52. //$mail->CharSet = 'iso-8859-1'; // Charset da mensagem (opcional)
  53. $mail->Subject = "Recuperação de senha"; // Assunto da mensagem
  54. $mail->Body = "Este é o corpo da mensagem de teste, em ".$pwrurl." <b>HTML</b>! :)";
  55. $mail->AltBody = "Este é o corpo da mensagem de teste, em Texto Plano! rn :)";
  56.  
  57. // Envia o e-mail
  58. $enviado = $mail->Send();
  59.  
  60. // Limpa os destinatários e os anexos
  61. $mail->ClearAllRecipients();
  62.  
  63. // Exibe uma mensagem de resultado
  64. if ($enviado) {
  65. echo "E-mail enviado com sucesso!";
  66. } else {
  67. echo "Não foi possível enviar o e-mail.";
  68. echo "<b>Informações do erro:</b> " . $mail->ErrorInfo;
  69. }
  70. }
  71. else
  72. echo "No user with that e-mail address exists.";
  73. }
  74. ?>
  75.  
  76. <form action="#" method="post" enctype="multipart/form-data" class="form-horizontal">
  77.  
  78. <fieldset class="form-group">
  79. <label for="email">Email</label>
  80. <input type="email" class="form-control" name="email" placeholder="Email" maxlength="70" size="70" required>
  81. </fieldset>
  82.  
  83. <input type="submit" class="btn btn-primary" name="recovery_pass" value="Recovery">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement