Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once("desabilita_erros.php");
- include("ConexaoBD.php");
- require_once("using_email/vendor/autoload.php");
- if (isset($_POST['ok'])) {
- $email_user = $server_mysql->real_escape_string($_POST['email1']);
- var_dump($email_user);
- if (!filter_var($email_user, FILTER_VALIDATE_EMAIL))
- $erro[] = "E-mail inválido!";
- //Verificar se email já existe
- $sql_code = "SELECT EMAIL_USU, NOME_USU FROM usuario WHERE EMAIL_USU = '".$email_user."' ";
- $exec_query = $server_mysql->query($sql_code) or die($server_mysql->error);
- $dados = mysqli_fetch_assoc($exec_query);
- $nome_user = $dados['NOME_USU'];
- $result = mysqli_num_rows($exec_query);
- if (mysqli_num_rows($exec_query) == 0)
- $erro[] = "Esse E-mail não existe em nossa base de dados!";
- if (count($erro) == 0) {
- $email_user = $dados['EMAIL_USU'];
- //Enviar email
- //Create a new PHPMailer instance
- $mail = new PHPMailer\PHPMailer\PHPMailer();
- //Tell PHPMailer to use SMTP
- $mail->isSMTP();
- //Informar que o email será em formato html
- $mail->IsHTML(true);
- //Informar que o charset do email em html será UTF-8
- $mail->CharSet = 'UTF-8';
- $mail->SMTPOptions = array(
- 'ssl' => array(
- 'verify_peer' => false,
- 'verify_peer_name' => false,
- 'allow_self_signed' => true
- )
- );
- //Enable SMTP debugging
- // 0 = off (for production use)
- // 1 = client messages
- // 2 = client and server messages
- $mail->SMTPDebug = 2;
- //Set the hostname of the mail server
- $mail->Host = 'smtp.gmail.com';
- // use
- // $mail->Host = gethostbyname('smtp.gmail.com');
- // if your network does not support SMTP over IPv6
- //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
- $mail->Port = 587;
- //Set the encryption system to use - ssl (deprecated) or tls
- $mail->SMTPSecure = 'tls';
- //Whether to use SMTP authentication
- $mail->SMTPAuth = true;
- //Username to use for SMTP authentication - use full email address for gmail
- $mail->Username = "lufonsecabarbosa95@gmail.com";
- //Password to use for SMTP authentication
- $mail->Password = "webdeveloper";
- //Set who the message is to be sent from
- $mail->setFrom('lufonsecabarbosa95@gmail.com', 'Sistema Agendamento de Reservas');
- //Set an alternative reply-to address
- //$mail->addReplyTo('replyto@example.com', 'First Last');
- //Set who the message is to be sent to
- $mail->addAddress($email_user, $nome_user);
- //Set the subject line
- $mail->Subject = 'Sistema Agendamento de Reservas';
- $corpo = file_get_contents('body_email_redefinir_senha.php');
- $link = "http://localhost/projeto-agendamento-reservas/LinkRedefinicaoSenha.php?email1={$email_user}";
- $corpoLink = str_replace('LinkRedefinicaoSenha.php', $link, $corpo);
- //Read an HTML message body from an external file, convert referenced images to embedded,
- //convert HTML into a basic plain-text alternative body
- $mail->msgHTML($corpoLink);
- //Replace the plain text body with one created manually
- $mail->AltBody = 'This is a plain-text message body';
- //Attach an image file
- //$mail->addAttachment('images/phpmailer_mini.png');
- //send the message, check for errors
- if (!$mail->send()) {
- echo "Erro ao enviar E-mail: " . $mail->ErrorInfo;
- } else {
- echo "E-mail enviado com sucesso!";
- //Section 2: IMAP
- //Uncomment these to save your message in the 'Sent Mail' folder.
- #if (save_mail($mail)) {
- # echo "Message saved!";
- #}
- }
- //Section 2: IMAP
- //IMAP commands requires the PHP IMAP Extension, found at: https://php.net/manual/en/imap.setup.php
- //Function to call which uses the PHP imap_*() functions to save messages: https://php.net/manual/en/book.imap.php
- //You can use imap_getmailboxes($imapStream, '/imap/ssl') to get a list of available folders or labels, this can
- //be useful if you are trying to get this working on a non-Gmail IMAP server.
- function save_mail($mail)
- {
- //You can change 'Sent Mail' to any other folder or tag
- $path = "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail";
- //Tell your server to open an IMAP connection using the same username and password as you used for SMTP
- $imapStream = imap_open($path, $mail->Username, $mail->Password);
- $result = imap_append($imapStream, $path, $mail->getSentMIMEMessage());
- imap_close($imapStream);
- return $result;
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="pt-br">
- <head>
- <title>Redefinição de Senha</title>
- <meta http-equiv="content-type" content="text/html; charset=utf-8">
- <link rel="stylesheet" type="text/css" href="_css/normalize.css"/>
- <link rel="stylesheet" type="text/css" href="_css/Estilo_RedefinirSenha.css"/>
- <!--[if lt IE 9]>
- <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- </head>
- <body class="body_form">
- <main class="container">
- <div class="content">
- <h1 class="titulo-form">Redefinição de Senha</h1>
- <form accept-charset="utf-8" action="" method="POST">
- <div class="form">
- <label>
- <span>E-mail:</span>
- <input type="email" name="email1" placeholder="Informe Seu E-mail:">
- </label>
- <div class="form_action">
- <input class="btn" type="submit" name="ok" value="Ok">
- </div>
- <div class="exibe_erros">
- <?php
- if (count($erro) > 0) {
- foreach ($erro as $valor)
- echo "<p>$valor</p>";
- }
- ?>
- </div>
- </div>
- </form>
- </div>
- </main>
- <footer class="footer-cad container">
- Desenvolvido Por Lucas Barbosa Fonseca
- </footer>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement