Send SMS using PHP and VOIP service

In this post you can see how to send SMS message with VOIP service using PHP. Almost all VOIP service providers are using same technic to send SMS over https protocol like this:
https://www.12voip.com/myaccount/sendsms.php?username=xxxxxxxxxx​&password=xxxxxxxxxx&from=xxxxxxxxxx&to=xxxxxxxxxx&text=xxxxxxxxxx
You can use this to put it in php and run it on server so other people can’t see your username nad password. This script can be used for lots of things like notifying people on new updates on your site (new comments on their post) or just to provide them with sending SMS.

PHP part of main index.php

<?php
error_reporting(E_PARSE);
if(isset($_POST['send_sms']))
{

$voipuser = "username"; //username
$pass = "pass"; //password
$from = "name or number"; // username or verified number from your voip acount
$to = $_POST['to']; // send to number
$txt = 'From:'.$_POST['from'].';'.$_POST['text']; // sms txt
$txt = str_replace(" ", "%20", $txt); // for te spaces in the sms , because the brousers automatic ad %20 for spaces

$url = 'https://www.12voip.com/myaccount/sendsms.php?username='.$voipuser .'&password=' .$pass .'&from=' .$from .'&to=' .$to .'&text=' .$txt;

$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0); // if you want to include heder
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); //if you don't want to output data from voip sms send page
// grab URL and pass it to the browser
$out = curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
$sended = 'SMS sent!';
}
?>

After PHP ther is javascript in index.php just for limiting number of characters in SMS because SMS can only send 160 simbols per SMS

<SCRIPT LANGUAGE="JavaScript">
function CountLeft(field, count, max) {
if (field.value.length > max)
field.value = field.value.substring(0, max);
else
count.value = max - field.value.length;
}
</script>

And here is a HTML part of script connected with javascript

<html>

<head><title>Send SMS with VOIP</title></head>
<body>
<center>
<div> <h2>Send SMS with VOIP</h2> </div>
<form action="" method="post">
<font size="3" face="arial, helvetica, sans-serif">
From: <input name="from" type="text"  value="name or number"onKeyDown="CountLeft(this.form.from, this.form.left ,154);" onKeyUp="CountLeft(this.form.from ,this.form.left,154);"/><br />
</br>
To: <input name="to" type="text" value="+385"/><br /><br />
txt:</br>
<textarea style="height:120px; width:250px" name="text" type="text" size="154" onKeyDown="CountLeft(this.form.text, this.form.left,154-this.form.from.value.length);" onKeyUp="CountLeft(this.form.text,this.form.left,154-this.form.from.value.length);"></textarea></br>
<input readonly type="text" name="left" size=3 maxlength=3 value="154"> characters left</font> </br> </br>
<input name="send_sms" type="submit" class="submit" value=" Send SMS " />

</form>
<div> <h2><?php echo $sended;?></h2> </div>
</center>
</body>
</html>

Thanks for supporting me. And leave a comment if something those not work.
And finaly you can download the script

 

You may also like...

3 Responses

  1. Neko says:

    Great post

  2. Nancy says:

    Thanks for the share!
    Nancy.R

Leave a Reply to Retta Cancel reply

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

Captcha Captcha Reload

This site uses Akismet to reduce spam. Learn how your comment data is processed.