How to Send Text Messages via PHP For Free

how to send sms from php

Hello, my friends, it's been a while that I didn't write any tutorial on PHP because I was busy with others tutorials and one of my friends asks me how to send SMS from PHP to mobiles for free, So I am here to tell you how you can send text message to mobile phones thought PHP, Using an SMS gateway.

What is SMS gateway ?

Well, SMS gateway is a short message service (SMS) which telecommunications providers to send SMS and receive messages from a Web browser.

SMS Gateway is free ?

No. but you can use the trial account to send limited SMS from below PHP script, There are many SMS gateway providers, In this tutorial we use the best one, You have to register a new free account to send to SMS using the Api. 
  • Recommended: Detect Mobile Devices Using PHP Class

  • Create Account and get the API

    First of all, Go to "" there you will see a "try it free green Email Box", enter your email and submit it.
    send sms with php
    Then go to your email and click activate link, It will redirect your active page where you need to add your info to active your free account.
    how to send text from php

    Once you have activated your account to will redirect your dashboard, Mouseover on help tab and click on "All Documentation" there you will see your Api Hash, copy and past it your notepad later will use this api code to send SMS.

    php sms send free

    Create The PHP Script

    To use this script you will need Xampp or the free web hosting site, You need to create the index.php file where you can paste the below PHP script codes 


     //Enter Your Txtlocal email or username
     $username = 'YOUR EMAIL';
     //Enter your txtlocal ApiHash
     $ApiHash = 'YOUR API HASH';
     //If user click on send button then run below codes
     if(isset($_POST['submit'] )=== true){
      $senderName = $_POST['name'];
      $sendTo  = $_POST['number'];
      $text   = $_POST['message'];
      //If above fields are not empty then then run below codes
      // Message details
      $number  = $sendTo;
      $sender  = urlencode($senderName);
      $message = rawurlencode($text);
       // Prepare data for POST request
      $data = array('username' => $username, 'hash' => $ApiHash, 'numbers' => $number, "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
      $data = json_decode($response ,true);


    Now you need to add your txtlocal ApiHash and you email in above code, now you need to add below HTML structure codes into your index.php after PHP closing tag "?>"


    <!doctype html>
      <link href=',700italic,700' rel='stylesheet' type='text/css'>
      <link rel="stylesheet" href="css/style.css"/>
    <div class="wrapper">
     <div class="container">
      <div class="main-heading">
        //if sms sent then show success message
         if(@$data['status'] === "success"){ 
         echo '<h1>"Your message has been sent."</h1>';
         echo '<h1>"Now Enter Your Mobile Number And Hit Send"</h1>';
      <form method="post">
      <div class="input-box">
         <input type="text" name="name" placeholder="Enter your name"></input>
         <input type="text" name="number" placeholder="Enter number with country code to send sms"></input>
         <textarea type="textarea" name="message" placeholder="Type Your Message"></textarea>
         <input type="submit" name="submit" value="SEND"></input>
     </div><!-- end container -->
     <div class="footer">
      <div class="footer-container">
       All credit goes to  <a style="text-decoration:underline;" href=""></a> team.
     </div><!-- end footer-->
    </div><!-- end wrapper -->

    Create the css folder and create the style.css file, Copy and paste below CSS codes

     font-family: 'Lora', serif;
     background: #19CDE4;
    ul li{
     margin:5px 5px;
     font-style: italic;
     text-shadow: -2px 2px 10px #9c9c9c;
     font-style: italic;
     text-shadow:-2px 2px 10px #9c9c9c;
     width: 1000px;
     margin-top: 40px;
     margin:0px auto;
    .main-heading h1{
    .last-heading h1{
     margin: 10px 0px;
    .link-heading h3{
    /*******************START INPUT **************/
    .input-box ul{
     margin: 100px auto;
     text-align: center;
     margin:10px auto;
    .input-box input[type="text"]{
     padding:10px ;
     color: #635f5f;
     border: 1px solid #ededed;
    .input-box textarea{
     color: #635f5f;
     border: 1px solid #ededed;
     padding: 10px;
    .input-box input[type="submit"]{
     border:1px solid #ccc;
     background: #fff;
     cursor: pointer;


    Now your site will look like below screenshot


    working php sms sending script


    Now you can send upto 10 free SMS to any mobile numbers make sure to add your country code to send sms,


    php can send sms for free


    Congratulations, You just created the SMS PHP app that can send sms to any numbers, If you liked this tutorial and learned from it then like and follow us on Twitter, Facebook.


  • Recommended: How To Make Wall Status System Like Facebook in PHP
  • Recommended: Creating Twitter Like Follow System Using PHP And JQuery
  • Comments

    1. Great and impressive article!! Got to learn and know more about web development. To know more refer create website for much more unique ideas.

    2. This comment has been removed by the author.

    3. I have read your blog its very attractive and impressive. I like it your blog.

      Sensing SMS is very important for today business. And this code is so useful.

    4. Sir if you dont mind can i request on how to receive the sms back to my web server?


    Post a Comment