Manual: How to send SMS via HTTP/HTTPS-request


 
  1. Parameters for text-SMS
  2. Statuscodes
  3. Receiving delivery reports
  4. Receiving replies
  5. Balance query
  6. Program examples

You can send an SMS by calling the URL in your browser or by submitting automatic HTTP-requests at the URL:

http://www.sms4.de/cgi-bin/sms_out.pl
The following CGI-parameters are processed:

 

1.) Parameters for text-SMS

Parameter Sample Description
handynr (mandatory) handynr=491743333333 Destination number. Destinations outside Germany must be in international format with the according country code without leading + or 00.
user (mandatory) user=XYZ Your SMS4.de username.
pwd (mandatory) pwd=XYZ User´s password.
kdnr (mandatory) kdnr=XY12345 Your SMS4.de customer ID. Get a free test account here
text (mandatory) text=test+a+German+umlaut+%F6 Text of SMS, max. 160 characters (ISO-8859-1).
tarif (optional) tarif=1 Possible tariff values are 1 or 7. For details see our Preisliste (tariff list)
(Default value is 1).
absender (optional) absender=Der-Peter The originator (sender) for the SMS, supported only with tariff 1:
6 to 11 alphanumeric characters (no special chars) or 6 to 14 numerals. With SMS to German landline phones only numerals are allowed.
Set the default originator at Einstellungen (settings).
sendezeit (optional) sendezeit=20240501354 Sending Time. This example means: Send SMS on 01.05.2024 at 13:54. The format is YYYYMMDDHHMM. Year Month Day Hour Minute without spaces, with leading zeroes for values <10 and without seconds. 24 Hour format.
v (optional) v=1 To request a unique id in the HTTP response please set v=1. You can use this Id e.g. for enquiries (corresponding to the Id in the CSV-Logfiles).
guthaben (optional) guthaben=1 To request the current prepaid balance (Euro) in the HTTP response please set guthaben=1 (only for prepaid customers).
replyto (optional) reply_to@someone-else.de Replies (tariff 7) and delivery reports (tariff 1 and 7) won´t be sent to the user´s email address but to the email given in REPLYTO.
test (optional) test=1 test=1 indicates test mode. SMS will not be sent out or billed.

Please substitute username, password and customer ID with your access data.
If you do not have access yet, please register here.

Sample request Text-SMS (GET)

The HTTP request must be URL-encoded. For example don´t use Ä but %C4 etc.
You can see the complete list here: urlencode-chart.
There are appropriate functions for url encoding in PHP, Perl and most other programming languages.
In PHP you can use fopen(), in Perl module HTTP::Request (read more in examples).

Line breaks in the text can be generated with %0A in the URL-String.
The parameters can be submitted using GET or POST.

 

 

Statuscodes

If the request was delivered successfully to our gateway, you get the following HTTP response:

<smsout>
  <status>0</status>
  <statustext>SMS erfolgreich versendet</statustext>
</smsout>
or in extended format with v=1:
<smsout>
  <status>0</status>
  <statustext>SMS erfolgreich versendet</statustext>
  <smsid>123456789</smsid>
</smsout>
or with displayed account balance guthaben=1:
<smsout>
  <status>0</status>
  <statustext>SMS erfolgreich versendet</statustext>
  <guthaben>23.35</guthaben>
</smsout>
Defined statuscodes:
 0 = SMS erfolgreich versendet
10 = Falsche Authentifzierung, Ungueltige Kombination User/Passwort/Kundennummer
11 = Falsche Authentifzierung, User fehlt
12 = Falsche Authentifzierung, Passwort fehlt
13 = Falsche Authentifzierung, Kundennr fehlt
20 = Handynummer fehlt
21 = Ungueltige Handynr
22 = Handynummer zu kurz
23 = Handynummer zu lang
25 = SMS Text fehlt
30 = Ungueltiger Tarif
31 = Ungueltige Kombination Tarif/Handynummer
40 = Test SMS aufgebraucht
41 = Guthaben aufgebraucht
42 = Monatslimit erreicht
51 = Ungueltige Absenderkennung
52 = Absenderkennung zu kurz
99 = Stoerung beim SMSC
Read more in our FAQ (German): Wie kann ich den Statuscode der HTTP-Schnittstelle verarbeiten?

 

4.) Receiving delivery reports

Pull: Documentation Pull DLRs via https

Push: Documentation push DLR via https

 

5.) Receiving replies

see (German): Handbuch Antworten �ber HTTP Push

 

6.) Balance query

see (German): Handbuch Guthabenabfrage �ber http oder https-Request

 

7.) Program examples

Sample code for PHP:

<?php
/* ================================================
Sample code for sending SMS via URL-request
www.sms4.de
===================================================*/

$kdnr  = "XY12345";	// Please substitute with your customer ID
$pw   = "8899";		// Please substitute with your password
$user = "Andre";	// Please substitute with your username


// originating number ( 6 to 11 chars oder 6 to 14 numbers )
// only with tariff 1
$absender="017488997766"; 

// number of destination, including country code and network
$handynr = "491741234567";

$text = "This is a test with PHP"; // Text of SMS 

$tarif = 1; // tariff 1 supports originator-ID, delivery notifications and direct termination

// build URL

$url = "http://www.sms4.de/cgi-bin/sms_out.pl?" 
 . "handynr="  . UrlEncode($handynr) 
 . "&user=" . UrlEncode($user) 
 . "&pwd=" . UrlEncode($pw) 
 . "&kdnr="  . UrlEncode($kdnr) 
 . "&text="  . UrlEncode($text)
 . "&tarif="    . UrlEncode($tarif)
 . "&absender="    . UrlEncode($absender)
 ;

// echo $url;

/* Call URL */ 

$message="";

if ( ($f = @fopen($url, "r")))  {
 $max_zeichen=256;
 $daten = fgets($f, $max_zeichen);
	while ($daten) {
	 $message.= $daten;
	 $daten = fgets($f, $max_zeichen);	    
	}
}
else { 
 echo "Error: URL $url could not be retrieved."; 
/* 
If fopen() fails, check the configuration of your server.
Option allow_url_fopen in php.ini must be set to TRUE. 
For more important hints about fopen see
http://www.php.net/manual/de/wrappers.http.php
*/
} 

echo $message;

?>

 

Sample code for Perl:

#!/usr/bin/perl

#############################################################
# Sample code for sending SMS via POST-Request
# www.sms4.de
#############################################################

# load Standard-CGI module
use CGI;

$kdnr= 'XY12345';# Please substitute with your customer ID
$pw= '8899';# Please substitute with your password
$user = 'Andre';# Please substitute with your username

# originating number ( 6 to 11 chars oder 6 to 14 numbers )
# only with tariff 1
$absender = 'Der-Peter';

# number of destination, including country code and network
$handynr = "491741234567";

$tarif = 1; # tariff 1 supports originator-ID, delivery notifications and direct termination

$text = 'This is a test with Perl';	# Text of SMS

# Call URL via POST

use HTTP::Request::Common;
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$res = $ua->request(
POST 'http://www.sms4.de/cgi-bin/sms_out.pl',
[
handynr => $handynr,
user => $user,
pwd => $pw,
kdnr => $kdnr,
text => $text,
tarif => $tarif,
absender => $absender
]

);

if ($res->is_error) {
# HTTP error
}

my $output = new CGI;
print $output->header();

# print response

if ($res->is_success) {
   print $res->content;
}
else {
   die $res->status_line;
}

 

Sample code for ASP:

<%@LANGUAGE="VBScript"%>
<%
' Sample code for sending SMS via POST-Request
' www.sms4.de

Dim xmlobj, url

Dim kdnr 
Dim pw 
Dim user
Dim absender
Dim handynr
Dim tarif
Dim text  

kdnr = "XY12345" 'Please substitute with your customer ID
pw = "8899" 'Please substitute with your password
user = "Andre" 'Please substitute with your username

'originating number ( 6 to 11 chars oder 6 to 14 numbers )
'only with tariff 1
absender = "Der-Peter"

'number of destination, including country code and network
handynr="491741234567"

tarif = 1 'tariff 1 supports originator-ID, delivery notifications and direct termination

text = "This is a test with ASP" 'Text of SMS 

'build URL
url = "handynr=" &  Server.URLEncode(handynr)
url = url & "&user=" &  Server.URLEncode(user)
url = url & "&pwd=" &  Server.URLEncode(pw)
url = url & "&kdnr=" &  Server.URLEncode(kdnr)
url = url & "&text=" &  Server.URLEncode(text)
url = url & "&tarif=" &  Server.URLEncode(tarif)
url = url & "&absender=" &  Server.URLEncode(absender)

'Call URL via POST
set xmlobj = Server.CreateObject("Msxml2.ServerXMLHTTP")
' set xmlobj = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
' set xmlobj = Server.CreateObject("Microsoft.XMLHTTP")
xmlobj.open "POST", "http://www.sms4.de/cgi-bin/sms_out.pl", false
xmlobj.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
xmlobj.Send url

'Print response
if (xmlobj.status <> 200 ) then
' HTTP error
else
	Response.write(xmlobj.responseText)
end if

set xmlobj = nothing
%>

 

Sample code for JSP:

<%@ page import="java.util.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>

<%

/* ========================================================
 Sample code for sending SMS via POST-Request
 www.sms4.de
===========================================================*/

String kdnr = "XY12345";		// Please substitute with your customer ID
String pw = "8899";		// Please substitute with your password
String user = "Andre";		// Please substitute with your username

// originating number ( 6 to 11 chars oder 6 to 14 numbers )
// only with tariff 1
String absender = "Der-Peter";

// number of destination, including country code and network
String handynr = "491741234567";

String tarif = "1"; // tariff 1 supports originator-ID, delivery notifications and direct termination
String text = "This is a test with JSP"; // Text of SMS

// build URL

String uri = "handynr=" + URLEncoder.encode(handynr);
uri = uri + "&user=" + URLEncoder.encode(user);
uri = uri + "&pwd=" + URLEncoder.encode(pw);
uri = uri + "&kdnr=" + URLEncoder.encode(kdnr);
uri = uri + "&text=" + URLEncoder.encode(text);
uri = uri + "&tarif=" + URLEncoder.encode(tarif);
uri = uri + "&absender=" + URLEncoder.encode(absender);


// Call URL via POST
try {
	URL http = new URL("http://www.sms4.de/cgi-bin/sms_out.pl");

	try {
		URLConnection connect = http.openConnection();
		connect.setDoOutput(true);
		connect.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
		PrintWriter output = new PrintWriter(connect.getOutputStream());
		output.println(uri);
		output.close();
		
		BufferedReader input = new BufferedReader(new InputStreamReader(connect.getInputStream()));
		String res = input.readLine();
		input.close();
		
		//Print response
		out.println(res);
	}
	catch (IOException ex) {
		//HTTP error
		out.println(ex);
	}
}
catch(MalformedURLException e) {
	out.println(e);
}

%>

 

Sample code for JAVA 6

Download Source
Parameters:
 -a,--a                 Absenderkennung
 -d,--debug             Debugmodus
 -h,--help              Diese Hilfe anzeigen.
 -hnr,--handynummer     Handynummer (Pflicht)
 -kdnr,--kundennummer   Kundennummer (Pflicht)
 -pw,--passwort         Passwort (Pflicht)
 -t,--tarif             Tarif 1 or 7
 -txt,--text            Text der SMS (Pflicht).
 -u,--user              User (Pflicht)
 
Sample call:
java SMS4 -hnr=491743333333 -u=XYZ -pw=XYZ -kdnr=XY12345 -txt="This is a text" -t=1
 

 

Sample code for Visual C# 2008

Download Source
Parameters:
 -a,--a         Absenderkennung
 -d,--d         Debugmodus
 -h,--h         Diese Hilfe anzeigen.
 -hnr,--hnr     Handynummer (Pflicht)
 -kdnr,--kdnr   Kundennummer (Pflicht)
 -pw,--pw       Passwort (Pflicht)
 -t,--t         Tarif 1-5
 -txt,--txt     Text der SMS (Pflicht).
 -u,--u         User (Pflicht)
 
Sample call:
SMS4 -hnr=491743333333 -u=XYZ -pw=XYZ -kdnr=XY12345 -txt="This is a text" -t=1
 

 

Sample code for C++ 6.0

Download Source
Parameters: User Password CustomerID Mobileno "Text" [Sender] [Tariff]
 
Sample call:
SMS4 XYZ XYZ XY12345 491743333333 "This is a text" Peter 1
 

 

Sample code for Visual Basic

Download Source
Private Sub CommandButton1_Click()

Dim res

' Call function SMS4: User, Password, CustomerID, Mobileno, Text, Sender, Tariff
res = SMS4("XYZ", "XYZ", "XY12345", "491743333333", "This is a text", "Der-Peter", 1)
MsgBox res

End Sub 

 

Sample code for command line

Call via Internet Explorer, reads Proxy-Settings. This way you can send out of corporate networks:
"C:\Program Files\Internet Explorer\iexplore.exe"  -extoff -private "https://www.sms4.de/cgi-bin/sms_out.pl?handynr=49174123456&user=abc&pwd=123=kdnr=abca&text=Dies+ist+ein+Text&tarif=1&absender=itsme"
Close window
taskkill /f /im iexplore.exe
with Wget:
wget -q -O - "http://www.sms4.de/cgi-bin/sms_out.pl?handynr=491743333333&user=XYZ&pwd=XYZ&kdnr=XY12345&text=This+is+a+text&tarif=1"

	or via POST-Request:

wget -q -O - --post-data "handynr=491743333333&user=XYZ&pwd=XYZ&kdnr=XY12345&text=This+is+a+text&tarif=1" http://www.sms4.de/cgi-bin/sms_out.pl
with Lynx:
lynx -source "http://www.sms4.de/cgi-bin/sms_out.pl?handynr=491743333333&user=XYZ&pwd=XYZ&kdnr=XY12345&text=This+is+a+text&tarif=1"
with cURL:
curl "http://www.sms4.de/cgi-bin/sms_out.pl?handynr=491743333333&user=XYZ&pwd=XYZ&kdnr=XY12345&text=This+is+a+text&tarif=1"

	or via POST-Request and SSL:

curl -k --data-urlencode "handynr=491743333333" --data-urlencode "user=XYZ" --data-urlencode "pwd=XYZ" --data-urlencode "kdnr=XY12345" --data-urlencode "text=This is a text via SSL" https://www.sms4.de/cgi-bin/sms_out.pl
mit .Net:

namespace HttpClientSample
{
    class Program
    {
        static void Main(string[] args)
        {

            // GetRequest("someurl");
            PostRequest("https://www.sms4.de/cgi-bin/sms_xml.pl");
            Console.ReadKey();
        }


        async static void PostRequest(string url)
        {
            string strxml = @"<httptosms>
                            <user>xxx</user>
                            <pwd>yyy</pwd>
                            <custid>zzz</custid>
                            <job>
                            <msg>Test XML SMS4 .net.</msg>
                            <tariff>1</tariff>
                            <sender>MeinName</sender>
                            <sms>
                            <to>017400000</to>
                            </sms>
                            </job>
                            </httptosms>
                            "
                                ;
            Console.WriteLine(strxml);
            Console.WriteLine();

            IEnumerable<KeyValuePair<string, string>> queries = new List<KeyValuePair<string, string>>()
            {
                new KeyValuePair<string, string>("xml", strxml)
            };

            HttpContent q = new FormUrlEncodedContent(queries);
            using (HttpClient client = new HttpClient())
            {
                using (HttpResponseMessage response = await client.PostAsync(url,q))
                {
                    using (HttpContent content = response.Content)
                    {
                        String mycontent = await content.ReadAsStringAsync();
                        Console.WriteLine(mycontent);
                    }
                }
            }
        }

        async static void GetRequest(string url)
        {
            using (HttpClient client = new HttpClient())
            {
                using (HttpResponseMessage response = await client.GetAsync(url))
                {
                    using(HttpContent content = response.Content)
                    {
                        string mycontent = await content.ReadAsStringAsync();
                        Console.WriteLine(mycontent);
                    }
                }
            }
        }
    }
}