Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (isset($_POST["recovery_pass"]))
- {
- if (filter_var($_POST["email"], FILTER_VALIDATE_EMAIL))
- {
- $email = $_POST["email"];
- }
- else
- {
- echo "email is not valid";
- exit;
- }
- // Check to see if a user exists with this e-mail
- $query = $conexao->prepare('SELECT email FROM users WHERE email = :email');
- $query->bindParam(':email', $email);
- $query->execute();
- $userExists = $query->fetch(PDO::FETCH_ASSOC);
- $conexao = null;
- if ($userExists["email"])
- {
- // Create a unique salt. This will never leave PHP unencrypted.
- $salt = "498#2D83B631%3800EBD!801600D*7E3CC13";
- // Create the unique user password reset key
- $password = hash('sha512', $salt.$userExists["email"]);
- // Create a url which we will direct them to reset their password
- $pwrurl = "$linkSite/recovery_pass/$password";
- require ("phpmailer/PHPMailerAutoload.php");
- // Inicia a classe PHPMailer
- $mail = new PHPMailer;
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'curruwilla@gmail.com'; // SMTP username
- $mail->Password = '4586928wW#0'; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
- $mail->Port = 587;
- // Define o remetente
- // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- $mail->setFrom = ('curruwilla@gmail.com'); // Seu e-mail
- // Define os destinatário(s)
- // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- $mail->AddAddress($email);
- $mail->IsHTML(true); // Define que o e-mail será enviado como HTML
- //$mail->CharSet = 'iso-8859-1'; // Charset da mensagem (opcional)
- $mail->Subject = "Recuperação de senha"; // Assunto da mensagem
- $mail->Body = "Este é o corpo da mensagem de teste, em ".$pwrurl." <b>HTML</b>! :)";
- $mail->AltBody = "Este é o corpo da mensagem de teste, em Texto Plano! rn :)";
- // Envia o e-mail
- $enviado = $mail->Send();
- // Limpa os destinatários e os anexos
- $mail->ClearAllRecipients();
- // Exibe uma mensagem de resultado
- if ($enviado) {
- echo "E-mail enviado com sucesso!";
- } else {
- echo "Não foi possível enviar o e-mail.";
- echo "<b>Informações do erro:</b> " . $mail->ErrorInfo;
- }
- }
- else
- echo "No user with that e-mail address exists.";
- }
- ?>
- <form action="#" method="post" enctype="multipart/form-data" class="form-horizontal">
- <fieldset class="form-group">
- <label for="email">Email</label>
- <input type="email" class="form-control" name="email" placeholder="Email" maxlength="70" size="70" required>
- </fieldset>
- <input type="submit" class="btn btn-primary" name="recovery_pass" value="Recovery">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement