How to send SMS to multiple recipients using PHP Codeigniter3

Send SMS to multiple recipients

Today we are going to learn How to Send SMS to Multiple Recipients Using PHP Codeigniter. Before that let us know what are the requirements we need to send text messages.


  1. SMS Gateway Account.
  2. API URL To Send Message.
  3. Working Mobile Number.
  4. Message

To Send SMS to multiple recipients in PHP we use CURL, where CURL is a PHP library used to get data from the server and transfer data to the server.

Here to send text message we use the API URL provided by the SMS Gateway and so we use CURL to send messages to multiple devices as CURL is also used to Perform API.

First we need to setup an account in your preferred SMS Gateway and complete the verification process, Before the verification process was very easy and anyone were be able to send SMS to multiple numbers.

But now the verification process is changed as too much of spamming and fake SMS are sent, So you need to verify your account and messages before using the API.

Send SMS to multiple recipients

 Steps to send SMS through Codeigniter 

STEP 1 : 

Create a PHP file with name Users.php in applications/controller and copy the below code.

defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

	public function  __construct() 
		parent:: __construct();
		error_reporting(E_ALL ^ E_NOTICE);  
	/* * *********************************************************************
	 * * Function name : index
	 * * Developed By : Tejaswi
	 * * Purpose  : This function used for SMS
	 * * Date : 09 August 2021
	 * * **********************************************************************/
	public function index()
        $fields = array('name','mobile');
        $whereCon = 'mobile != ""'; 

		$usersData = $this->sms_model->getData($fields,'users',$whereCon);

		$totalUsers = count($usersData );
        if($totalUsers > 0):
       	  foreach($totalUsers as $users):
       		$param['mobile'] 	=	$users['mobile'];
       		$param['name'] 		=	$users['name'];

            $message = 'Hello '.$users['name'].' Thankyou for visiting us.';

       		$this->sms_model->sendSMS($params,$message );

STEP 2 : 

Now create a model with name sms_model and copy the below code. Here i am using a single model to get data and send sms. You can use multiple models like separate model for sms related and separate model for CRUD data.

  • The first function getData is used to fetch data from users table whose mobile is not empty.
  • The second function sendSMS is used to send sms  to multiple recipients one each time.
if(!defined('BASEPATH')) exit('No direct script access allowed');
class Common_model extends CI_Model
	public function __construct()
	** Function name: getData
	** Developed By: Tejaswi
	** Purpose: This function used for get All Data
	** Date : 09 August 2021
	public function getData($fields=array(),$tableName='',$whereCon='')
		$query = $this->db->get();
		//echo $this->db->last_query();die;
		if($query->num_rows() > 0):
			return $query->result_array();
			return false;

    /* * *********************************************************************
	 * * Function name : sendSms 
	 * * Developed By : Tejaswi
	 * * Purpose  : This function used for send SMS to multiple recipients
	 * * Date : 09 August 2021
	 * * **********************************************************************/
	public function sendSms($phone='',$message='') {
		if(!empty($phone) && !empty($message)):
			curl_setopt_array($curl, array(
				CURLOPT_URL => ''.$message.'.&to='.$phone.'&sender=SENDER_NAME',

			$response = curl_exec($curl);

			echo $response;

Here the URL i  passed inside CURLOPT_URL will be different for different SMS gateway so you just need to paste your gateway provided URL and replace the variables $message & $phone with the static text message and static phone number.

This is the way to send SMS to multiple users, if you want to send text message to individual user just change the result_array to row array in the sms_model  for getData function and  remove the foreach loop in the controller.

This way you can send  SMS to multiple numbers using PHP code With CURL.

Let me know your reviews through comments and do not forget to share with your friends & colleagues whom might be useful.

And please subscribe to our notification to get instant updates.To subscribe just click on the allow button once you open our page.


Related articles:


For more updates:

Follow us on our Facebook page :

Do Follow my Instagram page for more updates :

Leave a Reply

Your email address will not be published. Required fields are marked *

The maximum upload file size: 2 MB. You can upload: image, document. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded.