phpsmpp

Invalid Command ID when trying to send SMS using SMPP and PHP


I received SMPP server details from a supplier so I can send SMS messages using their SMPP server to my customers. However, I seem to find little to no support on this for PHP. I have looked at the following github project but I keep getting the error 'Invalid Command ID' when I try to send. Can someone please have a look at my code and see if I am missing something?

I have connected to the SMPP server using telnet and connection is established successfully. I have tried stepping through the code as well, but can't identify the problem. I have checked every command id being passed in each call and they all seem to be valid as per the smpp website here, so I am at a loss. Any assistance would be greatly appreciated.

Github project: https://github.com/onlinecity/php-smpp

My code (ServerIP, PortNumber, Username and Password omitted):

<?php

require_once 'smppclient.class.php';
require_once 'gsmencoder.class.php';
require_once 'sockettransport.class.php';

// Construct transport and client
$transport = new SocketTransport(array('SMPP_SERVER_IP'),PORT_NUMBER);
$transport->setRecvTimeout(10000);
$smpp = new SmppClient($transport);

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

// Open the connection
$transport->open();
$smpp->bindTransmitter("USERNAME","PASSWORD");

// Optional connection specific overrides
SmppClient::$sms_null_terminate_octetstrings = false;
SmppClient::$csms_method = SmppClient::CSMS_PAYLOAD;
SmppClient::$sms_registered_delivery_flag = SMPP::REG_DELIVERY_SMSC_BOTH;

// Prepare message
$message = 'Hello World €$£';
$encodedMessage = GsmEncoder::utf8_to_gsm0338($message);
$from = new SmppAddress('MyAppName',SMPP::TON_ALPHANUMERIC);
$to = new SmppAddress(27798817281,SMPP::TON_INTERNATIONAL,SMPP::NPI_E164);

// Send
$messageID = $smpp->sendSMS($from,$to,$encodedMessage,null);

// Close connection
$smpp->close();

The stacktrace in php:

Fatal error: Uncaught SmppException: Invalid Command ID in /Applications/XAMPP/xamppfiles/htdocs/projects/smpp_test/src/libs/smpp/smppclient.class.php on line 622

( ! ) SmppException: Invalid Command ID in /Applications/XAMPP/xamppfiles/htdocs/projects/smpp_test/src/libs/smpp/smppclient.class.php on line 622

Call Stack

Time    Memory  Function    Location

1 0.0015 412144 {main}( ) .../test.php:0

2 2.2379 687472 SmppClient->close( ) .../test.php:35

3 2.2381 687472 SmppClient->sendCommand( ) .../smppclient.class.php:150


Solution

  • Try to use another library

    composer require glushkovds/php-smpp
    

    To send sms:

    <?php
    require_once 'vendor/autoload.php';
    
    $service = new \PhpSmpp\Service\Sender(['SMPP_SERVER_IP:SMPP_SERVER_PORT'], 'login', 'pass');
    $message = 'Hello World €$£';
    $smsId = $service->send(27798817281, $message, 'MyAppName');