Guest User

RedefinirSenha.php

a guest
Jan 15th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.33 KB | None | 0 0
  1. <?php
  2.  
  3. require_once("desabilita_erros.php");
  4. require_once("ConexaoBD.php");
  5. require_once("_email/vendor/autoload.php");
  6.  
  7. if (isset($_POST['ok'])) {
  8.  
  9.     $email_user = $server_mysql->real_escape_string($_POST['email1']);
  10.  
  11.     var_dump($email_user);
  12.  
  13.     if (!filter_var($email_user, FILTER_VALIDATE_EMAIL))
  14.         $erro[] = "E-mail inválido!";
  15.  
  16.     //Verificar se email já existe
  17.     $sql_code = "SELECT EMAIL_USU, NOME_USU FROM usuario WHERE EMAIL_USU = '".$email_user."' ";
  18.     $exec_query = $server_mysql->query($sql_code) or die($server_mysql->error);
  19.     $dados = mysqli_fetch_assoc($exec_query);
  20.     $nome_user = $dados['NOME_USU'];
  21.  
  22.     var_dump($nome);
  23.  
  24.     if (mysqli_num_rows($exec_query) == 0)
  25.         $erro[] = "Esse E-mail não existe em nossa base de dados!";
  26.  
  27.     if (count($erro) == 0) {
  28.        
  29.         //Enviar e-mail
  30.        
  31.         //Create a new PHPMailer instance
  32.         $mail = new PHPMailer\PHPMailer\PHPMailer();
  33.  
  34.         $mail->IsHTML(true);
  35.         $mail->CharSet = 'iso-8859-1';
  36.  
  37.         //Tell PHPMailer to use SMTP
  38.         $mail->isSMTP();
  39.  
  40.         $mail->SMTPOptions = array(
  41.             'ssl' => array(
  42.                 'verify_peer' => false,
  43.                 'verify_peer_name' => false,
  44.                 'allow_self_signed' => true
  45.             )
  46.         );
  47.  
  48.         //Enable SMTP debugging
  49.         // 0 = off (for production use)
  50.         // 1 = client messages
  51.         // 2 = client and server messages
  52.         $mail->SMTPDebug = 2;
  53.  
  54.         //Set the hostname of the mail server
  55.         $mail->Host = 'smtp.gmail.com';
  56.         // use
  57.         // $mail->Host = gethostbyname('smtp.gmail.com');
  58.         // if your network does not support SMTP over IPv6
  59.  
  60.         //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  61.         $mail->Port = 587;
  62.  
  63.         //Set the encryption system to use - ssl (deprecated) or tls
  64.         $mail->SMTPSecure = 'tls';
  65.  
  66.         //Whether to use SMTP authentication
  67.         $mail->SMTPAuth = true;
  68.  
  69.         //Username to use for SMTP authentication - use full email address for gmail
  70.         $mail->Username = "lufonsecabarbosa95@gmail.com";
  71.  
  72.         //Password to use for SMTP authentication
  73.         $mail->Password = "cadeirante95";
  74.  
  75.         //Set who the message is to be sent from
  76.         $mail->setFrom('lufonsecabarbosa95@gmail.com', 'Sistema Agendamento de Reservas');
  77.  
  78.         //Set an alternative reply-to address
  79.         //$mail->addReplyTo('replyto@example.com', 'First Last');
  80.  
  81.         //Set who the message is to be sent to
  82.         $mail->addAddress($email_user, $nome_user);
  83.  
  84.         //Set the subject line
  85.         $mail->Subject = 'Sistema Agendamento de Reservas - Redefinir de Senha';
  86.  
  87.         //Read an HTML message body from an external file, convert referenced images to embedded,
  88.         //convert HTML into a basic plain-text alternative body
  89.         $mail->msgHTML(file_get_contents('body_email.html'), __DIR__);
  90.  
  91.         //Replace the plain text body with one created manually
  92.         $mail->AltBody = 'This is a plain-text message body';
  93.  
  94.         //Attach an image file
  95.         //$mail->addAttachment('images/phpmailer_mini.png');
  96.  
  97.         //send the message, check for errors
  98.         if (!$mail->send()) {
  99.             echo "Erro ao enviar E-mail: " . $mail->ErrorInfo;
  100.         } else {
  101.             echo "Foi enviado um link em seu E-mail para a redefinição da sua senha!";
  102.             echo "E-mail enviado com sucesso!";
  103.             //Section 2: IMAP
  104.             //Uncomment these to save your message in the 'Sent Mail' folder.
  105.             #if (save_mail($mail)) {
  106.             #    echo "Message saved!";
  107.             #}
  108.         }
  109.  
  110.         //Section 2: IMAP
  111.         //IMAP commands requires the PHP IMAP Extension, found at: https://php.net/manual/en/imap.setup.php
  112.         //Function to call which uses the PHP imap_*() functions to save messages: https://php.net/manual/en/book.imap.php
  113.         //You can use imap_getmailboxes($imapStream, '/imap/ssl') to get a list of available folders or labels, this can
  114.         //be useful if you are trying to get this working on a non-Gmail IMAP server.
  115.         function save_mail($mail)
  116.         {
  117.             //You can change 'Sent Mail' to any other folder or tag
  118.             $path = "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail";
  119.  
  120.             //Tell your server to open an IMAP connection using the same username and password as you used for SMTP
  121.             $imapStream = imap_open($path, $mail->Username, $mail->Password);
  122.  
  123.             $result = imap_append($imapStream, $path, $mail->getSentMIMEMessage());
  124.             imap_close($imapStream);
  125.  
  126.             return $result;
  127.         }
  128.  
  129.     }
  130.  
  131. }
  132.  
  133. ?>
  134.  
  135. <!DOCTYPE html>
  136. <html lang="pt-br">
  137. <head>
  138.     <title>Redefinição de Senha</title>
  139.     <meta http-equiv="content-type" content="text/html; charset=utf-8">
  140.     <link rel="stylesheet" type="text/css" href="_css/normalize.css"/>
  141.     <link rel="stylesheet" type="text/css" href="_css/Estilo_RedefinirSenha.css"/>
  142.     <!--[if lt IE 9]>
  143.     <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
  144.     <![endif]-->
  145. </head>
  146. <body class="body_form">
  147. <main class="container">
  148.    
  149.     <div class="content">
  150.  
  151.         <h1 class="titulo-form">Redefinição de Senha</h1>
  152.  
  153.         <form accept-charset="utf-8" action="" method="POST">
  154.  
  155.             <div class="form">
  156.  
  157.                 <label>
  158.                     <span>E-mail:</span>
  159.                     <input type="email" name="email1" placeholder="Informe Seu E-mail:">
  160.                 </label>
  161.  
  162.                 <div class="form_action">
  163.                     <input class="btn" type="submit" name="ok" value="Ok">
  164.                 </div>
  165.  
  166.                 <div class="exibe_erros">
  167.                     <?php
  168.  
  169.                         if (count($erro) > 0) {
  170.                    
  171.                             foreach ($erro as $valor)
  172.                                 echo "<p>$valor</p>";
  173.  
  174.                         }
  175.  
  176.                     ?>
  177.                 </div>
  178.  
  179.             </div>
  180.            
  181.         </form>
  182.        
  183.     </div>
  184.  
  185. </main>
  186.  
  187. <footer class="footer-cad container">
  188.     Desenvolvido Por Lucas Barbosa Fonseca
  189. </footer>
  190.  
  191. </body>
  192. </html>
Add Comment
Please, Sign In to add comment