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:​&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


$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 = ''.$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
$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

function CountLeft(field, count, max) {
if (field.value.length > max)
field.value = field.value.substring(0, max);
count.value = max - field.value.length;

And here is a HTML part of script connected with javascript


<head><title>Send SMS with VOIP</title></head>
<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 />
To: <input name="to" type="text" value="+385"/><br /><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 " />

<div> <h2><?php echo $sended;?></h2> </div>

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!

Leave a 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.