<?php
require 'vendor/autoload.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/Exception.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = $_POST['name'] ?? '';
    $email = $_POST['email'] ?? '';
    $phone = $_POST['phone'] ?? '';
    $message = $_POST['message'] ?? '';

    $mail = new PHPMailer(true);

    try {
        $mail->isSMTP();
        $mail->Host = 'smtp.gmail.com'; 
        $mail->SMTPAuth = true;
        $mail->Username = 'asker244897@gmail.com'; 
        $mail->Password = 'wovivtrwmfzedsef';
        $mail->SMTPSecure = 'tls';
        $mail->Port = 587;

        $mail->setFrom($email, $name); 
        $mail->addAddress('asker244897@gmail.com');
        $mail->isHTML(false);
        $mail->Subject = 'Yeni iletişim mesajı';
        $mail->Body = "Ad & Soyad: $name\nE-posta: $email\nTelefon Numarası: $phone\nMesaj: $message";

        if ($mail->send()) {
            echo 'E-posta başarıyla gönderildi.';
        } else {
            echo 'E-posta gönderilirken bir hata oluştu: ' . $mail->ErrorInfo;
        }
    } catch (Exception $e) {
        echo 'E-posta gönderilirken bir hata oluştu: ' . $e->getMessage();
    }
}
?>