MaxI MaxI - 4 months ago 29
Linux Question

Php Function to send SMS via Kannel

I can now send an SMS via kannel. However this is done via headers eg:


I want to send an sms via a php function and I got the code below online but it doesn't work. (Kannel smsbox log shows no request):

function sendSmsMessage($in_number, $in_msg)
$url = '/cgi-bin/sendsms?username=' . CONFIG_KANNEL_USER_NAME
. '&charset=UCS-2&coding=2'
. "&to={$in_number}"
. '&text=' . urlencode(iconv('utf-8', 'ucs-2', $in_msg));

$results = file('http://'


Is there something wrong? I tried replacing the CONFIG_KANNEL_USER_NAME and the rest with the actual values but it still doesn't work. Open to suggestions.


I used cURL and it works 100% okay. file_get_contents does not work for me because I want to pass variables to the kannel url and file_get_contents does not process variables coz it insists on using single quotes(php treats it as a string value) instead of double quotes(php will parse the string checking for variables etc). Here is what i am currently doing assuming you already have your variables initialized somewhere:

$textmsg="Hello Stackoverflow Users!";

$cellphone_number = "+254xxxxxxx"


$ch= curl_init();
curl_setopt($ch, "http://localhost:13013/cgi-bin/sendsms?username=xxxxx&password=xxxxx&to=$cellphone_number&text=$encmsg");

This will work for the simple task of telling kannel to send an sms to a number. Took me a while to realize curl does not recognize spaces and special characters :-).