Advertisement
Guest User

RedefinirSenha

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