2

I have a codeigniter base website and I have tried making forgot password by Phone and Email using Codeigniter framework to change password notification.And email is already working but I don't know how to send message to phone using codeigniter??

And one of my friends told me that use Curl function to send message to phone.But I didn't have any prior idea about CURL function so I searched on google but I couldn't figure out how to do this.

Would you please give me proper suggestion about how to send message to phone using codeigniter.

Any kind of help would be highly appreciated.

Thanks in advance.

Jay Kareliya
  • 760
  • 7
  • 21

2 Answers2

3

Here is a simple code-igniter helper which you need to save as helpers/sendsms_helper.php

function sendsms($number, $message_body, $return = '0') {

$sender = 'SEDEMO'; // Can be customized

$smsGatewayUrl = 'http://springedge.com';

$apikey = '62q3xxxxxxxxxxxxxxxxxxxxxx'; // Need to change

$textmessage = urlencode($textmessage);

$api_element = '/api/web/send/';

$api_params = $api_element.'?apikey='.$apikey.'&sender='.$sender.'&to='.$number.'&message='.$textmessage;
$smsgatewaydata = $smsGatewayUrl.$api_params;

$url = $smsgatewaydata;

$ch = curl_init();

curl_setopt($ch, CURLOPT_POST, false);

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch);

curl_close($ch);

if(!$output){ $output = file_get_contents($smsgatewaydata); }

if($return == '1'){ return $output; }else{ echo "Sent"; }

}

How to use: You can use below function anywhere in project to send sms: Call sendsms function Ex. sendsms( '919918xxxxxx', 'test message' );

Please make sure to Load sendsms helper as $this->load->helper('sendsms_helper');

BSB
  • 2,270
  • 17
  • 26
  • You can get API key from [SMS gateway provider](https://www.springedge.com) for configuration. – BSB Aug 14 '16 at 19:20
0

There are many companies that provide api for the same. I have used twilio for some time and find it reliable. The code for same can be

<?php
    require "Services/Twilio.php";
    $AccountSid = "";  //get from twilio
    $AuthToken = "";   //get from twilio
    $client = new Services_Twilio($AccountSid, $AuthToken);
    $sms = $client->account->messages->sendMessage(
        $tNumber, // Your twilio number 
        $number, // Number you want to send to
        $message // Message you want to sms
    );

Hope this helps. Again there are many other services out there also that you can look into

xander cage
  • 219
  • 1
  • 4
  • 11