PHP code example

ViaNett provides you with code examples and programming objects, to help you connect to our gateway using the programming language of your choice. You are welcome to try these scripts. Sign up now to get 5 free SMS.

What is PHP?

PHP (PHP: Hypertext Preprocessor) is a widely-used general-purpose scripting language that is especially suited for Web development and which can be embedded into HTML.

Please visit the official PHP homepage if you want to know more.

PHP example code

This example code uses a ready-made object, based on the HTTP API. To use this script, simply register for free and get 5 free SMS.

Note: This example is based on PHP version 5 or later.

<?php 
 
include_once("ViaNettSMS.php"); 
 
// Declare variables. 
$Username = "YourUsername"
$Password = "YourPassword"
$MsgSender = "YourSender, example: a phone number like 4790000000"
$DestinationAddress = "Receiver - A phone number"
$Message = "Hello World!"
 
// Create ViaNettSMS object with params $Username and $Password 
$ViaNettSMS = new ViaNettSMS($Username$Password); 
try 
    // Send SMS through the HTTP API 
    $Result = $ViaNettSMS->SendSMS($MsgSender$DestinationAddress$Message); 
    // Check result object returned and give response to end user according to success or not. 
    if ($Result->Success == true) 
        $Message = "Message successfully sent!"
    else 
        $Message = "Error occured while sending SMS<br />Errorcode: " . $Result->ErrorCode . "<br />Errormessage: " . $Result->ErrorMessage; 
catch (Exception $e
    //Error occured while connecting to server. 
    $Message = $e->getMessage(); 
 
?> 
 
<html> 
    <head> 
        <title>ViaNettSMS Example</title> 
    </head> 
    <body> 
<?php 
echo "          <p><strong>SMS Result</strong><br />Status: $Message</p>"
?> 
    </body> 
</html> 

"ViaNettSMS" PHP object

ViaNett provides you with an object/class in PHP, based on the HTTP API. The source code is available for download.

Download source code

You need to log in to download the source code. Sign up now and get 5 free SMS messages.

Click here to download the source code.