php-smpp library can be used to make SMPP requests using PHP. This library's higher-level functions can be used to synchronously submit SMS to an SMS gateway or SMSC.
SMPP is the Short Message Peer-to-Peer protocol for conveying SMS operations. An SMPP account can easily be obtained for using the Tyr SMS Gateway or SMSC Simulator. The following are required to send SMS with SMPP:
- SMPP API account - SMPP API account for the Melrose Labs Tyr SMS Gateway
- SMPP API account (simulator) - SMPP API account for the Melrose Labs SMSC Simulator (simulate inbound and outbound SMS delivery)
Ruby is a programming language and can be used to quickly and easily add SMS support for programmatically sending and receiving SMS messages. The following are required to send SMS using PHP:
- PHP - PHP programming/scripting language
The following are required to send SMS with SMPP using PHP:
- php-smpp - PHP-based SMPP client library for sending and receiving SMS using SMPP v3.4
- Sockets - PHP socket extension
Create the file
sendsms.php containing the code below. Replace the hostname
PASSWORD values with those from your SMPP API account. Alternatively, replace
PASSWORD with those allocated to you for use with the Melrose Labs SMSC Simulator.
The following example PHP code opens an SMPP transmitter bind to
smscsim.melroselabs.com on port
2775 (SMPP port), and then sends the message
Hello World #$£ to mobile number
MelroseLabs. The message ID returned in
$messageID is that returned from the SMS gateway or SMSC after a successful submission. The SMPP system ID and password for the SMPP account are contained in
<?php require_once 'smppclient.class.php'; require_once 'gsmencoder.class.php'; require_once 'sockettransport.class.php'; // Construct transport and client $transport = new SocketTransport(array('smscsim.melroselabs.com'),2775); $transport->setRecvTimeout(10000); $smpp = new SmppClient($transport); // Open the connection $transport->open(); $smpp->bindTransmitter("SYSTEMID","PASSWORD"); // Prepare message $message = 'Hello World €$£'; $encodedMessage = GsmEncoder::utf8_to_gsm0338($message); $from = new SmppAddress('MelroseLabs',SMPP::TON_ALPHANUMERIC); $to = new SmppAddress(447712345678,SMPP::TON_INTERNATIONAL,SMPP::NPI_E164); // Send $messageID = $smpp->sendSMS($from,$to,$encodedMessage,$tags); // Close connection $smpp->close(); ?>
In order to receive delivery receipts for messages that are sent to a mobile, it is necessary to use a transceiver bind instead of a transmitter bind, or have a receiver bind in addition to a transmitter bind.