<?php

$errors  = '';
$myemail = 'fatossava47@gmail.com'; // Alıcı e-posta adresi

// Form verileri alınıyor
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    exit(1);
    $name    = $_POST['name'];
    $email   = $_POST['email'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];

    // Eksik alanlar kontrolü
    if (empty($name) || empty($email) || empty($subject) || empty($message)) {
        $errors .= "Error: Required fields are missing.\n";
    }

    // E-posta adresi doğrulaması
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $errors .= "Error: Invalid Email Address.\n";
    }

    // Eğer hata yoksa e-posta gönderme işlemi
    if (empty($errors)) {
        // E-posta başlıkları
        $to = $myemail;
        $email_subject = $subject;
        $email_body = "Name: $name\nEmail: $email\nSubject: $subject\nMessage:\n$message";

        // E-posta başlıkları
        $headers = "From: $email";

        // mail() fonksiyonu ile e-posta gönderme
        if (mail($to, $email_subject, $email_body, $headers)) {
            echo "Mesajınız başarıyla gönderildi.";
        } else {
            echo "Mesaj gönderilirken bir hata oluştu.";
        }
    } else {
        // Hata varsa ekrana yazdırma
        echo nl2br($errors);
    }
}
?>
<div class="section section-contact overlay overlay-dark-90" id="section5">
    <!-- contact bg start -->
    <div class="section-bg-contact"></div><!-- contact bg end -->
    <!-- section title start -->
    <div class="section-title section-title-left">
        <h4 class="section-title-subheading">
            Get in touch
        </h4>
        <div class="section-title-heading">
            Contact
        </div>
    </div><!-- section title end -->
    <!-- container start -->
    <div class="container sections">
        <!-- row start -->
        <div class="row">
            <!-- col start -->
            <div class="col-lg-12">
                <!-- section TXT start -->
                <div class="section-txt-contact">
                    <p>
                        CONTACT
                    </p>
                </div><!-- section TXT end -->
                <!-- section email start -->
                <div class="post-email-title">
                    <a href="mailto:fatossava47@gmail.com">OKAN UZUN</a>
                </div><!-- section email end -->
            </div><!-- col end -->
        </div><!-- row end -->
        <!-- row start -->
        <div class="row">
            <!-- col start -->
            <div class="col-lg-12">
                <!-- contact form start -->
                <div id="contact-form">
                    <form action="" id="form" method="post" name="send">
                        <!-- col start -->
                        <div class="col-sm-4 col-md-4 col-lg-4">
                            <input class="requiredField name" id="name" name="name" placeholder="Name" type="text">
                        </div><!-- col end -->
                        <!-- col start -->
                        <div class="col-sm-4 col-md-4 col-lg-4">
                            <input class="requiredField email" id="email" name="email" placeholder="Email" type="text">
                        </div><!-- col end -->
                        <!-- col start -->
                        <div class="col-sm-4 col-md-4 col-lg-4">
                            <input class="requiredField subject" id="subject" name="subject" placeholder="Subject" type="text">
                        </div><!-- col end -->
                        <div class="make-space">
                            <textarea class="requiredField message" id="message" name="message" placeholder="Message"></textarea>
                        </div>
                        <div>
                            <!-- contact form submit button start -->
                            <div class="contact-form-submit-wrapper">
                                <button class="c-btn inverse" type="submit"><span>Submit</span></button>
                            </div><!-- contact form submit button end -->
                            <!-- mobile end spacer start -->
                            <div class="mobile-only-end-spacer"></div><!-- mobile end spacer end -->
                        </div>
                    </form>
                </div><!-- contact form end -->
            </div><!-- col end -->
        </div><!-- row end -->
    </div><!-- container end -->
    <!-- copyright start -->

</div>