This PHP example demonstrates how to send SMS messages using the sms.net.bd SMS API in a PHP application. The provided sms_net_bd
class simplifies the process of interacting with the sms.net.bd SMS API.
Before using this example, make sure you have the following prerequisites:
- SMS API key. You can obtain this key by logging into your SMS account portal and accessing the API page.
git clone https://github.com/smsnetbd/sms-net-bd-php
cd sms-net-bd-php
This example includes a basic PHP script for sending SMS messages, checking SMS status, and getting your API balance.
<?php
$message = "Hello, this is a test message.";
$recipients = "01800000000,8801700000000";
$schedule = "2023-10-20 15:30:00"; // Optional
$senderId = "YourSenderId"; // Optional
$sms = new sms_net_bd('your_api_key_here');
// Send Single SMS
$response = $sms->sendSMS(
"Hello, this is a test SMS!",
"01701010101"
);
// Send Multiple Recipients SMS
$response = $sms->sendSMS(
"Hello, this is a test SMS!",
"01701010101,+8801856666666,8801349494949,01500000000"
);
// Send SMS With Sender ID or Masking Name
$response = $sms->sendSMS(
"Hello, this is a test SMS!",
"01701010101",
"sms.net.bd"
);
// Schedule SMS for future delivery
$response = $sms->sendScheduledSMS(
"Scheduled SMS",
"8801701010101",
$schedule // Date format: YYYY-MM-DD HH:MM:SS
);
// Schedule SMS for future delivery with Sender ID
$response = $sms->sendScheduledSMS(
"Scheduled SMS with date",
"8801701010101",
$schedule,
"sms.net.bd"
);
print_r($response);
?>
Replace the $message
, $recipients
, and $schedule
variables with your desired values.
<?php
$requestId = 12345; // Replace with the actual request ID
$sms = new sms_net_bd('your_api_key_here');
$statusResponse = $sms->getReport($requestId);
print_r($statusResponse);
Replace $requestId
with the actual request ID for which you want to check the status.
<?php
$sms = new sms_net_bd('your_api_key_here');
$balanceResponse = $sms->getBalance();
print_r($balanceResponse);
Replace
"your_api_key_here"
with your actual SMS API key, and customize the example usage according to your specific needs.
Ensure proper error handling in your application to handle potential issues with API requests and responses.
- If
error
value in response is 0, then the request was successfull - If
error
value in response is other than 0, then the request was not successfull and themessage
value in response will contain the error message
<?php
$sms = new sms_net_bd('your_api_key_here');
$response = $sms->sendSMS(
"Hello, this is a test SMS!",
"01701010101"
);
if ($response['error'] == 0) {
echo "SMS Sent Successfully";
} else {
echo "Error: " . $response['message'];
}
?>
Feedback, bug reports, and contributions are welcome. Feel free to open issues and pull requests.
For more information about sms.net.bd and its API, refer to the SMS API Documentation.