Very simple scripts to send SMS texts from your own systems and software
Our SMS API Gateway enables you to integrate the power of SMS into any application quickly and easily using any development language (PHP, ASP, .NET, Java etc). In a just a few simple lines of code you can easily build your SMS text and deliver to (almost) every mobile phone on the planet!
Thousands of clients connect to our SMS gateway every day - from blue chip organisations to bedroom hobbyists - its easy, low cost and you will be amazed how quicky you can integrate.
Accounts are 100% free, simply purchase text bundles as required. Should you find a lower price, call our Customer Care Team on 01244 573240 and we'll match or beat it.
<?php
// Configuration variables
$info = "1";
$test = "0";
// Data for text message
$from = "Jims Autos";
$selectednums = "447123456789";
$message = "Test with an ampersand (&) and a £5 note";
$message = urlencode($message);
// Prepare data for POST request
$data = "uname=".$uname."&pword=".$pword."&message=".$message
."&from=". $from."&selectednums=".$selectednums."&info=".$info."&test=".$test;
// Send the POST request with cURL
$ch = curl_init('https://www.txtlocal.com/sendsmspost.php'); //note https for SSL
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 Textlocal
curl_close($ch);
?>
<%
info = 1
test = 0
message = "Hello this is a test with a £5 note and an ampersand (&) symbol"
message = Server.urlencode(message) 'encode special characters (e.g. £, & etc) from = "Jims Autos"
address = "https://www.txtlocal.com/sendsmspost.php"
uname = "youremailaddress"
pword = "yourpassword"
selectednums = "447123456789"
url = address & "?uname=" & uname & "&pword=" & pword & "&message=" & message &_
"&from=" & from & "&selectednums=" & selectednums & "&info=" & info &_
"&test=" & test
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "POST", url, false
xmlhttp.send ""
msg = xmlhttp.responseText
response.write(msg)
set xmlhttp = nothing
%>
void Page_Load(Object Src, EventArgs E) {
myPage.Text = readHtmlPage("http://www.txtlocal.com/sendsmspost.php");
}
private String readHtmlPage(string url)
{
String result = "";
String message = HttpUtility.UrlEncode("Hello world!");
String strPost = "uname=email@domain.com&pword=yourpass&message=" + message +
"&from=SMITHS" + "&selectednums=447123456789&info=1";
StreamWriter myWriter = null;
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "POST";
objRequest.ContentLength = Encoding.UTF8.GetByteCount(strPost);
objRequest.ContentType = "application/x-www-form-urlencoded";
try{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);
}
catch (Exception e)
{
return e.Message;
}
finally {
myWriter.Close();
}
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()) )
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;
}
Private Function SendSMS_txtLocal(ByVal Test As Boolean, _
ByVal From As String, _
ByVal Message As String, _
ByVal SendTo As String, _
ByVal URL As String) As String
' Send a message using the txtLocal transport
Const TransportURL As String ="http://www.txtlocal.com/sendsmspost.php"
Const TransportUserNameAs String ="me@myemail.com"
Const TransportPasswordAs String ="mypassword"
Const TransportVerboseAs Boolean =True
Dim strPost As String
' Build POST String
strPost = "uname=" + TransportUserName _
+ "&pword=" + TransportPassword _
+ "&message=" + System.Web.HttpUtility.UrlEncode(Message) _
+ "&from=" + From _
+ "&selectednums=" + SendTo
If URL "" Then
strPost += "&url=" + URL
End If
If Test = True Then
strPost += "&test=1"
End If
If TransportVerbose =True Then
strPost += "&info=1"
End If
' Create POST
Dim request As WebRequest = WebRequest.Create(TransportURL)
request.Method = "POST"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(strPost)
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
' Get the response.
Dim response As WebResponse = request.GetResponse()
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServerAs String = reader.ReadToEnd()
' Clean upthe streams.
reader.Close()
dataStream.Close()
response.Close()
' Return result to calling function
If responseFromServer.Length > 0 Then
Return responseFromServer
Else
Return CType(response, HttpWebResponse).StatusDescription
End If
End Function
Private Function SendSMS_textlocal (From As String, SendTo As String, Message As String) as Variant
Dim username As String
Dim password As String
Dim result As String
Dim myURL As String, postData As String
Dim winHttpReq As Object
username = "test@txtlocal.co.uk"
password = "textlocalpassword"
Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
myURL = "http://www.txtlocal.com/sendsmspost.php"
postData = "uname=" + username + "&pword=" + password + "&message=" + Message +
"&from=" + From + "&selectednums=" + SendTo + "&test=0&info=0"
winHttpReq.Open "POST", myURL, False
winHttpReq.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
winHttpReq.Send (postData)
SendSMS_Textlocal = winHttpReq.responseText
End Function
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
public class SMSSender {
public String sendSms(String sToPhoneNo,String sMessage) {
try {
// Construct data
String data = "uname=" + URLEncoder.encode("textlocalusername****", "UTF-8");
data += "&pword=" + URLEncoder.encode("textlocalpassword****", "UTF-8");
data += "&message=" + URLEncoder.encode(sMessage, "UTF-8");
data += "&from=" + URLEncoder.encode("from email address", "UTF-8");
data += "&selectednums=" + URLEncoder.encode(sToPhoneNo, "UTF-8");
data += "&info=" + URLEncoder.encode("1", "UTF-8");
// Send data
URL url = new URL("https://www.txtlocal.com/sendsmspost.php");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
String sResult="";
while ((line = rd.readLine()) != null) {
// Process line...
sResult=sResult+line+" ";
}
wr.close();
rd.close();
return sResult;
} catch (Exception e) {
System.out.println("Error SMS "+e);
return "Error "+e;
}
}
}
#!/usr/bin/env python
import urllib
def sendSMS(uname, pword, numbers, sender, message):
params = {'uname': uname, 'pword': pword, 'selectednums': numbers,
'message' : message, 'sender': originator}
f = urllib.urlopen('https://www.txtlocal.co.uk/sendsmspost.php?'
+ urllib.urlencode(params))
return (f.read(), f.code)
resp, code = sendSMS('yourusername', 'yourpassword', '447123456789',
'Jims Autos', 'Test with an ampersand (&) and a £5 note')
print resp
#!/usr/bin/perl -T
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
# Txtlocal login details
my $uname = 'youremailaddress';
my $pword = 'yourpassword';
# Configuration details
my $test = "0"; # Set to 1 for testing
my $info = "1"; # Flag to switch on/off debug information.
# Data for text message
my $from = "Jims Autos";
my $selectednums = "447123456789";
# A comma separated list of mobile numbers
# with international dialling codes.
# Each number must be PURELY numeric.
my $message = "This is a test message"; # Text message content
my $ua = LWP::UserAgent->new();
my $res = $ua->request
(
POST 'http://www.txtlocal.com/sendsmspost.php',
Content_Type => 'application/x-www-form-urlencoded',
Content => [ 'from' => $from,
'uname' => $uname,
'pword' => $pword,
'info' => $info,
'test' => $test,
'selectednums'=> $selectednums,
'message' => $message
]
);
if ($res->is_error) { die "HTTP Error\n"; }
print "Response:\n\n" . $res->content . "\n\n";
The following is a list of variables that can be defined: (* indicates optional)
uname
Your Textlocal username (login email address. Sign up for a free test account)
pword *
Your Textlocal password. * Either pword or hash is required.
info *
Set to '1' to receive information about the request back to your application.
json *
Set to '1' to receive a JSON structured response about your request back to your application. The variable info must be set to 0 to receive JSON.
hash *
Your Textlocal hash (instead of password above). You can retrieve this from the Messenger->Documentation-All page. * Either pword or hash is required.
from
The Sender Name. This can be a word (up to 11 characters) or a number (up to 14 digits). If you set to 'xreplyx' then we will allocate a reply path number to the message, and any replies will arrive in your Simple Reply Service inbox within Messenger. You can then choose to forward these replies to email or your webserver via the Simple Reply Service settings page.
message
The text message body. This parameter will need to be URI-encoded.
selectednums
A comma-delimited list of mobile numbers in international format. Each number must be purely numeric, so no '+' symbols, hyphens or spaces. The numbers must be prefixed with their international dialling codes. For example, United Kingdom numbers would look like 447123456789.
group *
Contact group ID. If set, you can send your message to an entire Textlocal contact group. You can view a full list of group IDs in the Reports section of Messenger.
custom *
If set, this value will be recorded against the message batch and will passed back in the delivery receipts. This allows you to match delivery receipts to their corresponding messages.
rcpurl *
Receipt notification URL. If set, all delivery receipts for this message will be sent to the specified URL, instead of the one specified in your Textlocal Account Settings.
sched *
Message schedule time. If set, the message will be sent at the specified date and time. This parameter needs to be in the format YYYY-MM-DD-HH-MM-SS (e.g. 2012-01-20-11-30-00 for 11:30am on the 20th January 2012). Scheduled messages can be viewed, modified and deleted via the Messenger.
validity *
Message validity datetime. If set, this is the GMT time at which you wish the message to expire if has not yet been received by the phone. This parameter needs to be in the format MMDDHHmm and cannot be more than 48 hours into the future.
test *
Sets 'test mode'. Messages will not actually be transmitted, but will appear in the Reports->API Test area of messenger.
Debugging/Error Information
You can get two types of response from our Send SMS API - generic text or JSON. The following table shows the different outputs and responses accordingly.
Info (generic text)
TestMode
0 for live, 1 for testing
MessageReceived
The received message
ScheduledDate
The received scheduled SMS time
Custom
The received custom ID to be passed back in receipt
From
The FROM address used. If an invalid address has been passed (say, alphanumeric > 11 characters), it will default to the main account default address.
CreditsAvailable
Number of credits at start
MessageLength
Length of the message in characters
MessageCount
Number of messages (break at 160, 306, 459, 612)
NumberContacts
The number of comma separated numbers
CreditsRequired
Credits required for job
CreditsRemaining
Credits remaining after the job
Errors
Invalid Login
Incorrect username and password/hash
Invalid IP
If defined, you are coming from the wrong IP address
Invalid validity datetime (MMDDHHmm)
Validity time incorrectly formatted
Message Expired
Validity time is in the past
No content
Message Length zero
Invalid scheduled date format
Validity time incorrectly formatted
No mobile number(s)
No numbers defined
Message Too Long (<765 characters)
Message too long
No credit
No SMS credits
Not enough credit
Not enough credits for message
testmode - nothing sent
You entered test=1, therefore nothing has been sent, however the format of the request you sent was valid
JSON
Below is an example JSON response. If there is an error, Error will exist, and the text will be as above.
{
TestMode: 0,
MessageReceived: "This is a test message",
MessageCount: 1,
From: "Textlocal:default",
CreditsAvailable: 134,
MessageLength: 5,
NumberContacts: 1,
CreditsRequired: 1,
CreditsRemaining: 133
}
"As a business I am always looking to collaborate with professional and reliable companies. TxtLocal is one of them. I highly recommend them." - Lisa Erskine
Our website uses cookies, mmm.... These are small files that make our website work better. If you're unhappy with this you will need to change your cookie settings. Click here to view our privacy policy Or Click the x button to close.