cURL extension to PHP can be used to make REST calls.
REST requirements and resources
REST (REpresentational State Transfer) uses the HTTP protocol (HTTPS) for conveying SMS operations. A REST account can easily be obtained for using the Tyr SMS Gateway. REST uses JSON to carry the parameters that relate to the REST operation that you are performing. The following are required to send SMS with REST:
- REST API Key - API key for the REST SMS API of the Melrose Labs Tyr SMS Gateway
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
Create the file
sendsms.php containing the code below. Replace the
[API_KEY] value with the REST API key for your account.
The following example PHP code makes a REST HTTPS call to the Melrose Labs SMS API endpoint to send the message
Hello World #$£ to mobile number
MelroseLabs. The transaction ID for the message is returned by the endpoint after a successful submission.
<?php $data = array( "source"=>"MelroseLabs", "destination"=>"447712345678", "message"=>"Hello World #$£" ); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.melroselabs.com/sms/message", CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode($data), CURLOPT_HTTPHEADER => array( "x-api-key: [API_KEY]", "Content-Type: application/json" ), )); $response = curl_exec($curl); curl_close($curl); echo $response; ?>
Other APIs covered in our tutorials that can be used for sending and receiving SMS using PHP include: SMPP
Whatever the language or API, you can send SMS and receive SMS between applications and mobiles for a wide range of uses with a number of our services. Please consider using our Messaging, SMS gateway and Bulk SMS solutions. If you are interested in testing your application's SMS support and are using the SMPP protocol, then we recommend that you take a look at the Melrose Labs SMSC Simulator service that can simulate SMS message delivery to and from mobiles. The SMSC Simulator supports SMPP v3.3, v3.4 and v5, and has a high degree of SMPP protocol conformance. Later in 2020 we will be providing access to the Melrose Labs Tyr SMS Gateway for A2P, P2A, bulk, wholesale and business SMS, and for text marketing and other applications. The Melrose Labs Tyr SMS Gateway will support REST and SMPP APIs.