<?php
    if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS');
        header('Access-Control-Allow-Headers: token, Content-Type');
        header('Access-Control-Max-Age: 1728000');
        header('Content-Length: 0');
        header('Content-Type: text/plain');
        die();
    }

    header('Access-Control-Allow-Origin: *');
    header('Content-Type: application/json');

    $postData = file_get_contents('php://input');
    $data = json_decode($postData, true);

    if($data) {
        $message = "Фио: ". $data['fio'] ."\r\nE-mail: ". $data['email'] ."\r\nНомер телефона: ". $data['phone'] ."\r\nОбращение: ". $data['message'] ."\r\n";
    
        mail('talentcompany@yandex.ru', 'Заявка', $message);
    
        echo json_encode('{"status": "true"}');
    }
?>