<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

$_title         =  'Şifremi Unuttum';


?>
<div class="container-fluid adres_cubugu">
  <div class="row">
  	<div class="container">
  		<div class="row">
  			<div class="col-md-12">
  				<ul>
  					<li><a href="index.php"><i class="fa fa-home"></i> Anasayfa</a> <span><i class="fa fa-arrow-right"></i></span></li>
  					<li><a href="sifremi-unuttum">Şifremi Unuttum</a></li>
  				</ul>
  			</div>
  		</div>
  	</div>
  </div>
</div>

<section class="bg-dis">
	<div class="container">

        <div class="row mt-15">
          
          <div class="col-md-6 col-md-offset-3">

            <?php

              if($_POST){

                  $query = $db->prepare("SELECT * FROM kullanici where email=:email LIMIT 1");
                  $kullanici = $query->execute(array(":email"=>$_POST['email']));
                  $kullanici = $query->fetch(PDO::FETCH_ASSOC);
                  if($kullanici){


                      sms('Email: '.$kullanici['email'].' Şifre: '.$kullanici['sifre'],$kullanici['telefon']);


                      $mailbody = '<!DOCTYPE html>
                        <html>
                        <head>
                          <title>'.$cek['title'].'</title>
                          <meta charset="utf-8">
                        </head>
                        <body style="padding: 30px">
                          <div style="width: 98%;margin:0 auto;background: #02add9;padding: 1%;display: inline-block;border-radius: 10px">
                            <div style="width: 90%;float: left;background: #fff;padding: 10px 5% 20px 5%;">
                              <center><img src="'.$site.'upload/'.$cek['logo'].'" style="width: 200px"></center>
                              <table>
                                <tr>
                                  <th>Email Adresiniz</th>
                                  <th>Şifreniz</th>
                                </tr>
                                <tr>
                                  <td>'.$kullanici['email'].'</td>
                                  <td>'.$kullanici['sifre'].'</td>
                                </tr>
                              </table>
                            </div>
                          </div>
                          <style type="text/css">
                          body{font-family:arial}table{width:100%;border:1px solid #ddd}table tr{padding:0;margin:0}table tr th{border:1px solid #ddd;padding:0;margin:0;background:#02add9;color:#fff;padding:10px}table tr td{border:1px solid #ddd;padding:0;text-align:center;margin:0;border-spacing:0}
                          </style>
                        </body>
                        </html>';

                      $mail_ayar = $db->query("SELECT * FROM mail_ayar")->fetch(PDO::FETCH_ASSOC);

                      if(!empty($mail_ayar['host']) AND !empty($mail_ayar['mail']) AND !empty($mail_ayar['sifre'])){
                        require 'vendor/autoload.php';

                        $mail = new PHPMailer(true);

                        $mail->SMTPDebug = SMTP::DEBUG_SERVER;
                        $mail->isSMTP();
                        $mail->Host       = $mail_ayar['host'];
                        $mail->SMTPAuth   = true;
                        $mail->Username   = $mail_ayar['mail'];
                        $mail->Password   = $mail_ayar['sifre'];
                        $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
                        $mail->Port       = 587;
                        $mail->CharSet = 'UTF-8';
                        $mail->SMTPDebug = 0;   
                        $mail->setFrom($mail_ayar['mail'], $cek['title']);
                        $mail->addAddress($cek['siparis_email'], $cek['title']);
                        $mail->addAddress($_POST['email'], $_POST['ad'].' '.$_POST['soyad']);
                        $mail->isHTML(true);
                        $mail->Subject = 'Şifremi Unuttum';
                        $mail->Body    = $mailbody;
                        $mail->AltBody = '';
                        $mail->send();

                      echo '<center><img src="images/basari.png" style="width:150px"><br><br><span style="font-size:25px;color:red;font-weight:bold">Şifreniz mail adresinize gönderildi</span></center>';

                    }
                  }else{
                     echo '<center><img src="images/hata.png" style="width:150px"><br><br><span style="font-size:25px;color:red;font-weight:bold">Kullanıcı Bulunamadı</span></center>';
                  }

              }

            ?>

            <div class="alan" style="margin-bottom: 0px;border-bottom: 0px">
              <h3 style="margin-top: 0px;float: left;width: 100%;margin-bottom: 0px">Şifremi Unuttum</h3>
            </div>
            <div class="alan">
              <form action="" method="post">
                  <fieldset class="form-group mt-4 col-md-12">
                     <label>Email Adresiniz</label>
                     <input type="email" class="form-control" name="email" required="" placeholder="Email Adresiniz" value="">
                  </fieldset>
                  <fieldset class="form-group col-md-12">
                     <button class="btn icon-btn btn-success" style="width: 100%">Şifremi Gönder</button>
                  </fieldset>
                </form>
            </div>
          </div>

        </div>

  </div>
</section>
