Advertisement
Guest User

RedefinirSenha.php

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