Skip to content
PHP 5 based SMPP client library
Find file
New pull request
Pull request Compare This branch is 5 commits ahead, 39 commits behind master.

PHP-based SMPP client lib

This is a simplified SMPP client lib for sending or receiving smses through SMPP v3.4.

The socket implementation from Apache's Thrift is used for the transport layer components.

The library is divided into two parts:

  • protocol - containing everything related to SMPP
  • transport - the transport components from Apache's Thrift

Basic usage example

To send a SMS you can do:

$GLOBALS['SMPP_ROOT'] = dirname(__FILE__); // assumes this file is in the root
require_once $GLOBALS['SMPP_ROOT'].'/protocol/smppclient.class.php';
require_once $GLOBALS['SMPP_ROOT'].'/protocol/gsmencoder.class.php';
require_once $GLOBALS['SMPP_ROOT'].'/transport/tsocket.class.php';

// Simple debug callback
function printDebug($str) {
    echo date('Ymd H:i:s ').$str."\r\n";

try {
    // Construct transport and client, customize settings
    $transport = new TSocket('localhost',2775,false,'printDebug'); // hostname/ip (ie. localhost) and port (ie. 2775)
    $smpp = new SmppClient($transport,'printDebug');

    // Activate debug of server interaction
    $smpp->debug = true;        // binary hex-output
    $transport->setDebug(true); // also get TSocket debug

    // Open the connection

    // Optional: If you get errors during sendSMS, try this. Needed for ie. based servers.
    //SmppClient::$sms_null_terminate_octetstrings = false;

    // Optional: If your provider supports it, you can let them do CSMS (concatenated SMS) 
    //SmppClient::$sms_use_msg_payload_for_csms = true;

    // Prepare message
    $message = 'H€llo world';
    $encodedMessage = GsmEncoder::utf8_to_gsm0338($message);
    $from = new SmppAddress(GsmEncoder::utf8_to_gsm0338('SMPP Tést'),SMPP::TON_ALPHANUMERIC);
    $to = new SmppAddress(4512345678,SMPP::TON_INTERNATIONAL,SMPP::NPI_E164);

    // Send

    // Close connection

} catch (Exception $e) {
    // Try to unbind
    try {
    } catch (Exception $ue) {
        // if that fails just close the transport
        printDebug("Failed to unbind; '".$ue->getMessage()."' closing transport");
        if ($transport->isOpen()) $transport->close();

    // Rethrow exception, now we are unbound or transport is closed
    throw $e; 

To receive a SMS (or delivery receipt):

$GLOBALS['SMPP_ROOT'] = dirname(__FILE__); // assumes this file is in the root
require_once $GLOBALS['SMPP_ROOT'].'/protocol/smppclient.class.php';
require_once $GLOBALS['SMPP_ROOT'].'/transport/tsocket.class.php';

// Construct transport and client
$transport = new TSocket('',2775);
$transport->setRecvTimeout(60000); // for this example wait up to 60 seconds for data
$smpp = new SmppClient($transport);

// Activate binary hex-output of server interaction
$smpp->debug = true;

// Open the connection

// Read SMS and output
$sms = $smpp->readSMS();
echo "SMS:\n";

// Close connection

Implementation notes

  • You can't connect as a transceiver, otherwise supported by SMPP v.3.4
  • The SUBMIT_MULTI operation of SMPP, which sends a SMS to a list of recipients, is not supported atm. You can easily add it though.
  • The thrift sockets will return false if the timeout is reached (after version 0.6.0). You can use this feature to implement an enquire_link policy. If you need to send enquire_link for every 30 seconds of inactivity, set a timeout of 30 seconds, and send the enquire_link command if readSMS() returns false.
  • The examples above assume that the SMSC default datacoding is GSM 03.38.
  • Remember to activate registered delivery if you want delivery receipts (set to SMPP::REG_DELIVERY_SMSC_BOTH / 0x01).
  • Both the SmppClient and transport components support a debug callback, which defaults to error_log. Use this to redirect debug information.
Something went wrong with that request. Please try again.