Skip to main content

Send SMS with PHP

You can use the example below to send bulk, single or OTP sms from your PHP software.

function sendRequest($url, $xml) {

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, 'Content-Type: text/xml');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);

return curl_exec($ch);
}

$api_key = '';
$api_hash = '';
$sender = 'APITEST';

$xml = <<<EOS
<request>
<authentication>
<key>{$api_key}</key>
<hash>{$api_hash}</hash>
</authentication>
<order>
<sender>{$sender}</sender>
<sendDateTime></sendDateTime>
<message>
<text><![CDATA[Test Message]]></text>
<receipents>
<number>531277xxxx</number>
</receipents>
</message>
</order>
</request>
EOS;


$result = sendRequest(
'http://api.iletimerkezi.com/v1/send-sms',
$xml
);

die('<pre>'.var_export($result,1).'</pre>');