<?php
require_once 'assets/inc/config.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/src/Exception.php'; // Exception.php dosya yolu
require 'PHPMailer/src/PHPMailer.php'; // PHPMailer.php dosya yolu
require 'PHPMailer/src/SMTP.php'; // SMTP.php dosya yolu

$mail = new PHPMailer(true);
$responseMessage = '';
if ($_POST) {
    try {
        // Server settings
        $mail->CharSet = 'UTF-8';
        $mail->SMTPDebug = 0; // 0: debug kapalı, 1: debug açık
        $mail->isSMTP();
        $mail->Host = SUNUCU; // SMTP sunucu adı
        $mail->SMTPAuth = true; // SMTP Doğrulama
        $mail->Username = EPOSTA; // SMTP kullanıcı adı
        $mail->Password = PASSWORD; // SMTP kullanıcısının şifresi
        $mail->SMTPSecure = 'tls'; // Şifreleme
        $mail->Port = PORT; // SMTP Port

        // Gönderen bilgilerini ayarla
        $mail->setFrom(EPOSTA, 'Geridönüşüm');
        $mail->addAddress(EPOSTA, 'Info');

        // Yanıt adresini formdan al
        if (isset($_POST['form_email']) && isset($_POST['form_name'])) {
            $mail->addReplyTo($_POST['form_email'], $_POST['form_name']);
        } else {
            throw new Exception('Form verileri eksik!');
        }

        $mail->isHTML(true);
        $mail->Subject = 'Yeni İletişim Mesajı';
        $mail->Body    = '<p>Gönderen: ' . htmlspecialchars($_POST['form_name']) . '</p>' .
                          '<p>Email: ' . htmlspecialchars($_POST['form_email']) . '</p>' .
                          '<p>Telefon: ' . htmlspecialchars($_POST['form_phone']) . '</p>' .
                          '<p>Konu: ' . htmlspecialchars($_POST['form_subject']) . '</p>' .
                          '<p>Mesaj: ' . nl2br(htmlspecialchars($_POST['form_message'])) . '</p>';

        // Üçüncü taraf SMTP sunucusu ile barındırma sunucusu entegrasyonu için gerekebilir
        $mail->SMTPOptions = array(
            'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            )
        );

        $mail->send();
        $responseMessage = "Mesajınız başarıyla gönderildi. Teşekkür ederiz!";
    } catch (Exception $e) {
        $responseMessage = 'Mesajınız iletilemedi. Hata: ' . htmlspecialchars($e->getMessage());
    }
}
include "header.php";
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>İletişim</title>
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
    <style>
        #map { height: 400px; width: 100%; }

        /* Popup Message Styles */
        #popup-message {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: #fff;
            padding: 20px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            z-index: 1000;
            display: <?php echo !empty($responseMessage) ? 'block' : 'none'; ?>;
        }

        .popup-content {
            text-align: center;
        }

        .popup-content p {
            margin-bottom: 20px;
        }

        .popup-content button {
            padding: 10px 20px;
            background-color: #007bff;
            color: #fff;
            border: none;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <!--Start breadcrumb area paroller-->
    <section class="breadcrumb-area">
        <div class="breadcrumb-area-bg" style="background-image: url(assets/images/breadcrumb/breadcrumb-1.jpg);"></div>
        <div class="container">
            <div class="row">
                <div class="col-xl-12">
                    <div class="inner-content">
                        <div class="breadcrumb-menu" data-aos="fade-down" data-aos-easing="linear" data-aos-duration="1500">
                            <ul>
                                <li><a href="index.php">Ana Sayfa</a></li>
                                <li class="active">İletişim</li>
                            </ul>
                        </div>
                        <div class="title" data-aos="fade-up" data-aos-easing="linear" data-aos-duration="1500">
                            <h2>İletişim</h2>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!--End breadcrumb area-->

    <!--Start Google Map Style2 Area-->
    <section class="google-map-area">
        <div class="auto-container">
            <div class="contact-page-map-outer">
                <!-- Google Maps iframe -->
                <iframe
                    src="link"
                    width="100%" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade">
                         
                        </div>
                </iframe>
                <!-- Contact Information Box -->
            </div>
        </div>
    </section>
    <!--End Google Map Style2 Area-->

    <!--Start Main Contact Form Area-->
    <section class="main-contact-form-area">
        <div class="container">
            <div class="row">
                <div class="col-xl-6 col-lg-6">
                    <div class="contact-info-box">
                        <div class="sec-title">
                            <div class="sub-title">
                                <h3>Dokun ve bizimle iletişime geç!</h3>
                            </div>
                            <h2>İletişim Seçeneklerimiz</h2>
                        </div>
                        <div class="contact-info-list">
                            <ul>
                                <li>
                                    <div class="icon">
                                        <span class="icon-telephone"></span>
                                    </div>
                                    <div class="text">
                                        <p>Telefon ile iletişime geç.</p>
                                        <h4><a href="tel:+905380320786">+(90) 538 032 07 86</a></h4>
                                    </div>
                                </li>
                                <li>
                                    <div class="icon">
                                        <span class="icon-email-1"></span>
                                    </div>
                                    <div class="text">
                                        <p>E-posta Gönder</p>
                                        <h4><a href="mailto:info@geridonusum.com">info@geridonusum.com</a></h4>
                                    </div>
                                </li>
                                <li>
                                    <div class="icon">
                                        <span class="icon-pin-1"></span>
                                    </div>
                                    <div class="text">
                                        <p>Konumumuzu ziyaret edin</p>
                                        <h4>Adres</h4>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <div class="col-xl-6 col-lg-6">
                    <div class="contact-form contact-form--style2">
                        <div class="sec-title">
                            <div class="sub-title">
                                <h3>Mesaj Gönder</h3>
                            </div>
                            <h2>Bize Bir Mesaj Gönder</h2>
                        </div>

                        <form id="contact-form" name="contact_form" class="default-form2" method="post" action="">
                            <div class="row">
                                <div class="col-xl-12">
                                    <div class="form-group">
                                        <div class="input-box">
                                            <input type="text" name="form_name" id="formName" placeholder="İsim Soyisim" required="">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xl-12">
                                    <div class="form-group">
                                        <div class="input-box">
                                            <input type="email" name="form_email" id="formEmail" placeholder="Eposta Adresi" required="">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xl-12">
                                    <div class="form-group">
                                        <div class="input-box">
                                            <input type="text" name="form_phone" id="formPhone" placeholder="Telefon Numarası">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xl-12">
                                    <div class="form-group">
                                        <div class="input-box">
                                            <input type="text" name="form_subject" id="formSubject" placeholder="Konu">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xl-12">
                                    <div class="form-group">
                                        <div class="input-box">
                                            <textarea name="form_message" id="formMessage" placeholder="Mesajınız..."></textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xl-12">
                                    <div class="form-group">
                                        <button class="btn-one" type="submit" data-loading-text="Please wait...">Mesaj Gönder</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                        <!-- Popup Message -->
                        <div id="popup-message">
                            <div class="popup-content">
                                <p><?php echo htmlspecialchars($responseMessage); ?></p>
                                <button onclick="closePopup()">Kapat</button>
                            </div>
                        </div>
                    </div>
                </div>
 
            </div>
        </div>
    </section>
    <!--End Main Contact Form Area-->

    <script>
        // Function to show the popup
        function showPopup() {
            document.getElementById('popup-message').style.display = 'block';
        }

        // Function to close the popup
        function closePopup() {
            document.getElementById('popup-message').style.display = 'none';
        }

        // Show popup if response message exists
        <?php if (!empty($responseMessage)) { ?>
            showPopup();
        <?php } ?>
    </script>

</body>
</html>

şunu deneyin hocam son olarak