<?php
function debugs($data = '', $email = false, $emails = ['A.Younis@taqnyat.sa'])
{
    if ($data == '') {
        $data = file_get_contents('php://input');
    }




    if ($email) {
        $to = implode(',', $emails);
        $subject = "mail log" . date("Y-m-d H:i:s");
        $headers = "From: aaaa@taqnyat.sa" . "\r\n";
        mail($to, $subject, addslashes($data . "\n\n\n"), $headers);
    }

    if (is_array($data)) {
        $data = json_encode($data);
    }

    $base = 'https://taqnyat.requestcatcher.com';
    $method = 'POST';
    $header = [];
    API($base, $method, $data, $header);
}
function API($base, $method, $data, $headers = [])
{

    $curl = curl_init();
    curl_setopt_array(
        $curl,
        [
            CURLOPT_URL => $base,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 5,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_CUSTOMREQUEST => $method,
            CURLOPT_POSTFIELDS => $data,
            CURLOPT_HTTPHEADER => $headers,
        ]
    );
    $response = curl_exec($curl);
    curl_close($curl);
    return $response;
}

function APINew($url, $stringToPost)
{

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $stringToPost);
    $result = curl_exec($ch);
    return $result;
}
