Tutorial section - SMS
Send SMS with SMPP using PHP
Sending SMS with the SMPP API using the PHP programming languageRelated
SMPP Load BalancerSMPP Load Test tool
SMSC Simulator
SMPP SMS Gateway platform
Tyr SMS Gateway
SMS Code Bench
The 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 requirements and resources
SMPP is the Short Message Peer-to-Peer protocol and is used by applications for sending and receiving SMS. An SMPP client can be used to connect to an SMSC or SMS gateway using the SMPP protocol. An SMPP account, including special Developer accounts, can quickly and easily be obtained for using the Melrose Labs Tyr SMS Gateway or SMSC Simulator. The following are required to send SMS with SMPP:
- SMPP Protocol [reference]
Short Message Peer-to-Peer Protocol v3.3, v3.4 and v5 specifications and guides - SMPP Client [tool]
Browser-based SMPP client supporting SMPP v3.x and v5 via Web Sockets
PHP requirements and resources
PHP is a programming language and can be used to quickly and easily add SMS support for programmatically sending and receiving SMS messages. Use it for transactional messaging and notifications between your application and mobiles. The following are required to send SMS using PHP:
- PHP
PHP programming/scripting language
Requirements and resources
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
SMPP Flow
The code connects to the server, then establishes an SMPP transmitter bind by sending a bind_transmitter
SMPP PDU. It receives a bind_transmitter - resp
with a positive "Ok" acknowledgement.
A submit_sm
PDU is then sent by the code to send the message. The message ID for the submission is returned in the submit_sm - resp
.
The session is then closed by the code sending an unbind
PDU, which is acknowledged with a unbind - resp
. The TCP session is then closed.
Code
Create the file sendsms.php
containing the code below. Replace the hostname smscsim.melroselabs.com
, port 2775
, SYSTEMID
and PASSWORD
values with those from your SMPP API account. Alternatively, replace SYSTEMID
and PASSWORD
with those allocated to you for use with the Melrose Labs SMSC Simulator or the smpp.org 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 447712345678
from 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 SYSTEMID
and PASSWORD
respectively.
sendsms.php
<?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);
// Close connection
$smpp->close();
?>
Delivery receipts
To receive delivery receipts, use a transceiver bind instead of a transmitter bind, or have a receiver bind in addition to a transmitter bind.
Using in production
Whatever the language or API, you can send SMS and receive SMS between applications and mobiles for a wide range of uses with any of the trusted and reliable CPaaS services from Melrose Labs. Take a look at our Messaging, SMS gateway and Bulk SMS solutions, and sign-up for a Developer account on our Tyr SMS Gateway service to try us out.
We provide a wide range of CPaaS services and infrastructure to organisations, including cloud platforms that enable you to run your own SMS gateway.
Get in contact with us to find out more about CPaaS voice, messaging, video and identity from Melrose Labs.
Testing
For testing your application's SMS support when using the SMPP protocol, we recommend starting with the Melrose Labs SMSC Simulator service to simulate SMS message delivery to mobiles (MT SMS) and simulate SMS messages from mobiles (MO SMS). The SMSC Simulator supports SMPP v3.3, v3.4 and v5.
SMSC SimulatorFor live testing and delivery to mobiles, use the reliable and dependable Melrose Labs Tyr SMS Gateway for A2P, P2A, bulk, wholesale and business SMS, text marketing and other uses. The Melrose Labs Tyr SMS Gateway supports REST and SMPP APIs.
Tyr SMS GatewayAlternative APIs and languages
Other APIs covered in our tutorials that can be used for sending and receiving SMS using PHP include: REST
Other languages covered in our tutorials that can be used for sending and receiving SMS with SMPP include: Python, Java, C++, C#, Perl, Go, Node.js, Ruby