Program – [Project File] Send SMS Using PHP
First Thing
- First of all, you have to go to Text Local website, which we have given the link to this line. Visit
- After this you have to sign up.
- After completing your profile, you have clicked on the API key from Setting.
- Now you have to create a new API key.
- For testing, you have to leave both boxes blank and Save New Key.
After That Download This Zip File (Important File)
[Project File] Send SMS Using PHP
Index.php
You have to focus on 44 and 51 number line and change it with your API Key and Country Code…..
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Send Free SMS</title> <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20src%3D%22%2F%2Fmaxcdn.bootstrapcdn.com%2Fbootstrap%2F4.0.0%2Fjs%2Fbootstrap.min.js%22%3E%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<script>" /> <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20src%3D%22%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fjquery%2F3.2.1%2Fjquery.min.js%22%3E%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<script>" /> <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20src%3D%22script.js%22%3E%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<script>" /> <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cstyle%3E%0A%20%20%20%20.red%7B%0A%20%20%20%20%20%20%20%20color%3Ared%3B%0A%20%20%20%20%7D%0A%3C%2Fstyle%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<style>" title="<style>" /> </head> <body> <div class="container"> <form method="POST"> <div> <br style="clear:both"> <div class="form-group col-md-4"> <label for="number" id="messageLabel">Mobile Number</label> <input type="tel" id="number" name="number" pattern="[0-9]{10}" required class="form-control"> </div> <div class="form-group col-md-4 "> <label id="messageLabel" for="message">Message</label> <textarea class="form-control input-sm " type="textarea" id="message" placeholder="Message" maxlength="140" rows="7" name="msg"></textarea> <span class="help-block"><p id="characterLeft" class="help-block ">You have reached the limit</p></span> </div> <br style="clear:both"> <div class="form-group col-md-2"> <button class="form-control input-sm btn btn-success disabled" id="btnSubmit" name="btnSubmit" type="submit" style="height:35px">Send</button> </div> </div> </form> </div> <?php require('Textlocal.class.php'); try { // Account details extract($_POST); $apiKey = "enter Your API HERE"; $Textlocal = new Textlocal(false, false, $apiKey); if (isset($btnSubmit)) { if (isset($number) && isset($msg)) { if (!empty($number) && !empty($msg)) { // Message details $no_inti = 'country code'.$number;// enter your country code in the place of string like for india 91 $numbers = array($no_inti); $sender = urlencode('TXTLCL'); //TXTLCL is default sender for tesing don't change until your project isn't ready.... $message = rawurlencode($msg); $response = $Textlocal->sendSms($numbers, $message, $sender); // add $sched = null, $test = true in sendSms() for testing purpose..... otherwise you will losse 10 free sms... if ($response->status == 'success') { echo "Message Sent Succesfully"; } if ($response->status == 'Failure') { echo "Can't Sent Message<br/>"; } } } } } catch (Exception $e) { echo($e->getMessage()); } ?> </body> </html>
Script.js
$(document).ready(function(){ $('#characterLeft').text('140 characters left'); $('#message').keyup(function () { var max = 140; var len = $(this).val().length; if (len >= max) { $('#characterLeft').text('You have reached the limit'); $('#characterLeft').addClass('red'); $('#btnSubmit').addClass('disabled'); } else { var ch = max - len; $('#characterLeft').text(ch + ' characters left'); $('#btnSubmit').removeClass('disabled'); $('#characterLeft').removeClass('red'); } }); });
Tag:- php code to send sms from localhost, send sms using php source code
Thanks for the informative blog, Needed it! You did a great job. Keep going.