Sample PHP Code for Sending SMS

  1. $api_key = 'xxxxxxxxxxxxxxxxx';
  2. $phone = '02xxxxxxxx';
  3. $sender_id = 'senderid';
  4. $message = 'sms message';
  5. $url = "http://sms.nasaramobile.com/api?api_key=$api_key&&sender_id=$sender_id&&phone=$phone&&message=".urlencode($message)."";
  6. //send message and get response
  7. $response = file_get_contents($url);
  8. if($response == '1801'){
  9. echo "message sent successfully";
  10. }
  11. elseif($response == '1802') {
  12. echo "message sending failed";
  13. }
  14. elseif($response == '1803') {
  15. echo "invalid login phone or password given";
  16. }
  17. elseif($response == '1804') {
  18. echo "not enough sms credit";
  19. }
  20. elseif($response == '1805') {
  21. echo "sender id must be more than 1 charater and less than 12 characters";
  22. }
  23. elseif($response == '1806') {
  24. echo "phone number must be more than 8 characters";
  25. }


PHP Sample Code To Check SMS Credit

You can check your SMS credit via the API. Error codes are returned alone while the read data is returned in json format.

The credit is returned in the format :


Data contains the credit.

URL : http://sms.nasaramobile.com/api/accounts/credit
Method : GET
  1. <?php
  2. $api_key = 'xxxxxxxxxxxxxxxxxxxxxxx';
  3. $url = "http://sms.nasaramobile.com/api/accounts/credit?api_key=$api_key";
  4. $response = file_get_contents($url);
  5. if($response == '1903'){
  6. echo "there was an error<hr>";
  7. }
  8. elseif($response == '1902') {
  9. echo "this api key does not exist<hr>";
  10. }
  11. elseif($response == '1901') {
  12. echo "Api key must be posted to execute request<hr>";
  13. }
  14. elseif(json_decode($response)->status == '1000'){
  15.     $result = json_decode($response);
  16.     echo $credit = $result->data;
  17. }