-1

How to send an sms to a phone number using php- Codeigniter?

We have an sms-gateway-provider and I have a user-id, password and api-url. What I wanted to know is, how would I use these in a codeigniter framework, could I get a sample codes? I just wanted the proper codes to achieve this in Codeigniter.

Mary
  • 197
  • 1
  • 15
Madhu
  • 2,643
  • 6
  • 19
  • 34
  • `our sms services`... what services? do you have an sms-gateway-provider? Without more info, no one is going to be able to help you... – RichardBernards Nov 20 '14 at 10:24
  • @madhu, what have you tried so far? Research included. Thanks. – Eduard Uta Nov 20 '14 at 10:25
  • You should ask this question to them who give services at your company or someone who already worked on it. more helpful. – Sarz Nov 20 '14 at 10:26
  • yea, we have an sms-gateway-provider and i have a user-id, password and api-url. now what i wanted to know is, how would i use these in a codeigniter framework. could i get a sample codes? – Madhu Nov 20 '14 at 10:32
  • 2
    I doubt there's anything special you need to do, just because it's codeigniter. You probably just need to do a `file_get_contents('http://yourapiurl?password=xxx&message=xxx')` or similar. Check your provider's API docs. – rjdown Nov 20 '14 at 10:39
  • Please ask this from your sms service provider :) because probably they are the guys who knows this best..its not a staright forward thing to send sms using CI, first you have to build the app using CI, and then should integrate the sms api into the app as a module. So first talk to your api provider and get a documentation. Hope this makes sense. – Nimeshka Srimal Nov 20 '14 at 11:15
  • what is your sms gateway provider? – pregmatch Nov 22 '14 at 16:58

3 Answers3

4

There is simple sms helper available for codeigniter

Copy below file from github as sendsms_helper.php in /application/helpers/

https://github.com/SpringEdgeIndia/codeigniter-sms-api/

Usage:

Load sendsms helper as $this->load->helper('sendsms_helper');

Call sendsms function Ex. sendsms( '919918xxxxxx', 'test message' );
Semy Tech
  • 121
  • 5
2

its a simple script

$sending = http_post("your_domain", 80, "/sendsms", array("Username" => $uname, "PIN" => $password, "SendTo" => $Phone, "Message" => $usermessage));

and bingo

Ijaz Ahmed Bhatti
  • 736
  • 1
  • 7
  • 26
1

you must use cURL for better security in CodeIgniter. this function works fine for sending SMS.

function sms_code_send($number='',$message='')
    {
    $username   = 'username';
    $password   = '*******';
    $originator = 'sender name';
    $message    = 'Welcom to ......, your activation code is : '.$message;
    //set POST variables
    $url = 'http://exmaple.com/bulksms/go?';

    $fields = array(
      'username'   => urlencode($username),
      'password'   => urlencode($password),
      'originator' => urlencode($originator),
      'phone'      => urlencode($number),
      'msgtext'    => urlencode($message)
     );

    $fields_string = '';

    //url-ify the data for the POST
    foreach($fields as $key=>$value)
    {
      $fields_string .= $key.'='.$value.'&';
    }

    rtrim($fields_string,'&');

    //open connection
    $ch = curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POST,count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

    //execute post
    $result = curl_exec($ch);

    //close connection
    curl_close($ch);
    return $result;
}
AbdulAhmad Matin
  • 1,047
  • 1
  • 18
  • 27