<?php
function smsGonder($telefon, $mesaj)
{
    $kullaniciAdi = '8508403082';
    $sifre        = 'Adgebs1234.';
    $baslik       = '8508403082';

    $xml = '<?xml version="1.0" encoding="UTF-8"?>
    <mainbody>
      <header>
        <company>'.$baslik.'</company>
        <usercode>'.$kullaniciAdi.'</usercode>
        <password>'.$sifre.'</password>
        <type>1:n</type>
        <msgheader>'.$baslik.'</msgheader>
      </header>
      <body>
        <msg><![CDATA['. $mesaj .']]></msg>
        <no>'. $telefon .'</no>
      </body>
    </mainbody>';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.netgsm.com.tr/sms/send/xml");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type: text/xml; charset=UTF-8',
        'Content-Length: ' . strlen($xml)
    ]);

    $response = curl_exec($ch);
    curl_close($ch);

    // PHP 7 uyumlu "starts with" kontrolü
    if (substr(trim($response), 0, 2) === "00") {
        return true;
    } else {
        return $response;
    }
}
?>