I have recently come across CYTA (Cyprus) web sms api. It has been around for a while from what I can understand. Don’t confuse this with Web Sms (previously cybee if I am not mistaken) which was around since forever. It uses a RESTful api, in which you can programmatically send an sms from your application or web application/website using your preferred programming language. Well, not really any language since the sample code has examples only for 3 programming languages, and all are Microsoft’s. By the way, as of this writing, and to my knowledge, this is the only source code available in php to accomplish this task. The documentation provides useful information, although I don’t find it to be fully documented.
So, time to dive in. First, you should know that you need a mobile phone number from cyta, if you want to use this service. Then, you need to sign up, if you don’t already have an account. After you sign in go here to view and manage your settings. You should take notice of your secret key, as you will be needing it later. Before moving on, I should also inform you that you are allowed 10 free sms per day. After that, your phone number, (which you used to sign up) will be charged 0.02 euro / sms. Each time you can sent up to 500 sms. Of course, you can only sent sms to phone numbers in Cyprus. International mobile numbers are not allowed.
Before viewing the code, you should read the documentation to have an idea how it works and what the server responses mean. So here is my php code.
$url = "https://www.cyta.com.cy/cytamobilevodafone/dev/websmsapi/sendsms.aspx"; $xml = file_get_contents("body.xml"); $headers = array( "POST HTTP/1.1", "Content-type: application/xml; charset=\"utf-8\"", "Content-length: " . strlen($xml), "Connection: close", ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, POST); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $data = curl_exec($ch); echo $data; curl_close($ch);
The code is pretty straight forward. We set cyta’s server url, read additional information from an xml file, and set the headers. Then, we use curl to send the request. Below is the xml file.
<?xml version="1.0" encoding="UTF-8"?> <websmsapi> <version>1.0</version> <username>YOUR_USERNAME</username> <secretkey>YOUR_SECRETKEY</secretkey> <recipients> <count>1</count> <mobiles> <m>9XXXXXXX</m> </mobiles> </recipients> <message>Hello from Cyta web sms api</message> <language>en</language> </websmsapi>
A few things to notice here are obviously your username and secret key. You get these from your account page. The number of recipients must match the number of mobile phones listed. The server will respond with an xml indicating an error code or a success. You can view the xml in your browser’s developer tools console. Your browser tab will only show the message or code. For example the browser will show this.
But if you dive to the developer console, in the elements tab (in chrome) you can view the source which if you expand it will be this.
Here, a status of 0 means success! This is of course a proof of consept code. Normally you would wrap this up in a function and place it in your custom functions php file. Then you would include that in your main project and call the function. You would also had to automatically create the xml file with the appropriate phone numbers. The source code is up on github. Feel free to browse and use it in your own projects. If you have any questions or comments, please use the comments below. I hope this will be helpful to someone. I would also like to know if anyone has implemented this in another language or framework, so please let me know!