RunCodes
Programming & Tech

How to Send Free SMS From PHP Using SMS API?[With Source Code]

27 9,609

As you all know guyz, the era that we are living is an era of internet, so everyone is hanging on their PC all the time. Everyday we are sending some SMS to our friends in order to inform something to them. So, if there is some method that can send SMS for free, everyone gonna use that method and loved it. Today, in this tutorial we are gonna discuss about that method but we are gonna send that message using our own program (PHP). And also if you wanna send the message to your friends without displaying your number and name, this tutorial is for you! sometime we are in the mode of cracking jokes and wanna fool your friends or sending some threatening message(only for entertainment purpose otherwise it will be illegal) you can use this method.

“This tutorial may be very useful for those who want to integrate SMS features in their project which is developed in PHP”.

For sending SMS using SMS API approach: you have to do two task:

1.   Selecting Carrier

2.    Writing PHP script

[sociallocker]
we are selecting txtlocal as our carrier. So, All you have do is go to http://www.txtlocal.co.uk and there you need to create one account. after creating account. (you need to fill up some of your information and txtlocal will send you a verification email into your email and verify your account [watch the video for detail]). After completing this step, go to https://control.txtlocal.co.uk/docs/ and scroll down, at the bottom of the page you will see Send SMS via PHP; click that link and copy the code from there and edit as in the following manner or simply copy the below code but you need to provide your own hash key when you run this project.

After doing this, you complete the task of selecting your carrier. Now write the following piece of code in any text editing software, i am using dream weaver cc. and saved this php file in .php extension in your localhost and run (Note: your php file will not execute in the same way you run your html file, because PHP is server side scripting language so you need to have any server application to run this file.  watch this video to configure site and testing server in dream weaver cc: https://youtu.be/L4ex3S8BVCo  or read from here: click here)

Source Code: 


<!doctype html>
<?php if(isset($_POST['abc'])){ 
// Authorisation details. 
$username = $_POST['username']; 
$hash = $_POST['hash']; 
// Config variables. Consult http://api.txtlocal.com/docs for more info. 
$test = "0"; 
// Data for text message. This is the text message data. 
$sender = $_POST['sender']; // This is who the message appears to be from. 
$numbers = $_POST['num']; // A single number or a comma-seperated list of numbers 
$message = $_POST['mess']; 
// 612 chars or less 
// A single number or a comma-seperated list of numbers 
$message = urlencode($message); 
$data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test; 
$ch = curl_init('http://api.txtlocal.com/send/?'); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$result = curl_exec($ch); // This is the result from the API 
curl_close($ch); 
echo($result); 
} 
?>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form method="post" action="apismsphp.php">
<table align="center">
<tr>
<td>username:</td>
<td><input type="text" name="username" placeholder="enter your username"></td>
</tr>
<tr>
<td>hash:</td>
<td><input type="text" name="hash" placeholder="enter your hash key"></td>
</tr>
<tr>
td>sender:</td>
<td><input type="text" name="sender" placeholder="enter your name"></td>
</tr>
<tr>
<td>number:</td>
<td><input type="text" name="num" placeholder="enter your number"></td>
</tr>
<tr>
<td>message:</td>
<td><textarea name="mess" placeholder="enter your message"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="abc" value="send"></td>
</tr>
</table>
</form>
</body>
</html>

May be after sending 10 SMS your credit will be finished! but don’t be sad you can send more and more SMS but you need to create another account with another email account in www.txtlocal.co.uk ! that’s it. you may not be that much happy to hear this (sending only 10 SMS) but don’t forget you are able to send these 10 SMS for free and also there is one line “To get something, you must lose something”. it means you have to spend some time in creating account in txtlocal.co.uk in order to send free SMS.

[/sociallocker]

Finally, if you guyz think, this is awesome tutorial and help you in some extend please share this tutorials with your all friend so that they can know about this method of sending SMS!

watch the video:

 

Show Comments (27)