Ana içeriğe geç

PHP ile SMS Gönder

PHP ile yapılmış yazılımlarınızdan toplu, tekli veya OTP sms göndermek için aşağıdaki örnekten faydalanabilirsiniz.

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);
}

$username = '';
$password = '';
$sender = 'APITEST';

$xml = <<<EOS
<request>
<authentication>
<username>{$username}</username>
<password>{$password}</password>
</authentication>
<order>
<sender>{$sender}</sender>
<sendDateTime></sendDateTime>
<message>
<text><![CDATA[Test Mesaji]]></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>');