Faster PHP Cloud Hosting

Howdy developer, all our modern web applications need to verify mobiles numbers to ensure that we don’t get any fake user in our database. Therefore today I taught to write a post on sending sms in php by using textlocal.

Before learning to send sms in php firstly let me tell you what is textlocal.

What is Textlocal

Basically, textlocal is an sms gateway for sending sms to users individually or in a bulk. You can use it for sending promotional sms, transactional sms, business sms, etc. It also provides other sms marketing features but we don’t need to discuss those features.

create a free textlocal account ->

I personally love textlocal as they are reliable and they also provide really cheap pricing. Therefore I think that they are one of the best sms gateways out there.

Now that you know what textlocal is we will move further and see how to send sms in php.

Sending SMS in PHP

If you are already familiar with using API in php then sending sms in php is very easy. We just need to include in the textlocal class and then class the call the textlocal class.

Requirments –

The textlocal.class.php requires php 5.2 or higher and the PHP cURL module installed.

Download PHP SMS Sending Class

You need to download the textlocal class according to the textlocal website you are using.

Download the official php sms sending class from here –

Textlocal India               –  Download

Textlocal UK & Others   –  Download

Let’s Get Started

Now that you have got everything set up we can now start writing the code for sending your sms in php.

You may directly copy the below code and then modify it according to your requirements.

Basic Usage

<?php require 'textlocal.class.php'; $textlocal=new textlocal('[email protected]','e215398a8820abd2c7a11a6cd5b1009d'); // Enter your textlocal login email and the generated api key $textlocal->sendSms('917788990011','Hello , This your message','SENDER'); // Enter the reciveres mobile no , the message, and the Senders Name 

This is just a basic code and you may use it only for testing or only if you want to send a single message.

Enhanced Usage

I would recommend you to use this code in your actual web applications.

<?php // Account details $apiKey = urlencode('Your apiKey'); // Message details $numbers = array(447123456789, 447987654321); $sender = urlencode('Jims Autos'); $message = rawurlencode('This is your message'); $numbers = implode(',', $numbers); // Prepare data for POST request $data = array('apikey' => $apiKey, 'numbers' => $numbers, "sender" => $sender, "message" => $message);

// Send the POST request with cURL
$ch = curl_init('');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

// Process your response here
echo $response;

The above code is really easy to understand and you may read the comments to understand it better.

PHP Send Email To SMS

Previously I had shown you how to send an email php by using the php mail function but now I will be showing you how to convert a sent email to an sms by using textlocal.

If you don’t want to use other features offered by textlocal API then I would recommend you to use the email to SMS service for sending sms ;

Before sending an email firstly you need to enable/active Email 2 SMS.

Activating Email 2 SMS

To active Email 2 SMS simply log in to your textlocal account and then go to settings >> Email 2 SMS and then check the Active Email 2 SMS and then click on save settings.

I would recommend you to also check require password in subject field for better security.

Once you have done it you are good to proceed further.

Email Domains –

If you are using Textlocal India then you need to send the email to [email protected] else if you are using Textlocal UK or others then you have to send the email to [email protected] .

Let’s Send The SMS Via Email

Now you can send the email to send it as an SMS to any mobile number.

If you don’t know how to send emails in php you can read my post covering it over here.

For sending sms via emails we will be using the code given below

// Set the proper email domain 
$email_domain = "" ; 

// numbers to which you want to send the SMS 
$numbers  = array("918828578855","912246651324","9126646651324"); 

// Set The Senders Name 
$sender = "YourdevME" ; 

// your message body if it exceeds more then 160 chars will be sent in each SMS 
$message = "Hello, .MY SMS..... Thank You." ; 

// Your Authorized Email Address
$from = "From: [email protected]" ; 
$subject = "Sender=$sender pass=$pass" ; 
$recivers = array() ; 
foreach($number  as $no){ 
    $recivers[] = $no.'@'.$email_domain ; 
$to = implode(", ", $recivers); 
mail($to,$subject,$message,$from) ;

We have used the php implode function for converting the emails array to string so that you can send SMS in bulk.

Wow !! So I hope you may have successfully sent SMS using php.For preventing mistakes or any other issues I would recommend you to use the codes which I have given in this article.

And if you have any doubts or difficulties regarding sending sms in php or using textlocal sms API do ask me in the comments section below.