Sending SMS with PHP and TextMagic: An A to Z guide
Step 1: Creating a TextMagic account
In order to send SMS to mobile phones, you need to use a third-party service. In this tutorial, I’m using a service called TextMagic to send SMS. There are lots of other services to do so, but I’ve tested Textmagic and I’m very happy with it so far.
To use TextMagic, you have to create an account. Gohere and register. Prices starts at $27 for 200 SMS (13.5 cents per sms)
Step 2: Configure your API account
Once you have created your TextMagic account, go to My services → API → Password. You need to generate an API password in order to be able to send SMS from your website. Just enter your account password and click on “Generate API password”.
Once done, you have to download the API files. Go tothis page and click on the “Download” button to get the API files. Extract the
textmagic-sms-api-php.zip
file and upload all of its content to your server.Step 3: Let’s code!
Now, we have to create a function that will send the SMS throught the TextMagic API. The following code, taken from TextMagic website is the easiest way to send a SMS using the TextMagic API.
require('textmagic-sms-api-php/TextMagicAPI.php'); $api = new TextMagicAPI(array( "username" => "yourTextMeUsername", "password" => "yourTextMePassword" )); $text = "Your message here"; // Use this number for testing purposes. This is absolutely free. $phones = array(9991234567); $results = $api->send($text, $phones, true);
So how does this code works? First, I’m including the TextMagic API. Then we have to instantiate a
TextMagicAPI
object. To do so, you need your TextMagic username as well as your API password.$phones
is an array that can contains how many phone numbers as you want. Useful for bulk text messaging!
Finally, the SMS is sent using the
sent
method. For testing purposes, you can use the 9991234567
number provided by TextMagic. It is totally free!
Now, how to make sure your SMS has been sent? Easy, just see if
$results
is true:if ($results = $api->send($text, $phones, true)){ echo "SMS sent successfully!"; }
You’re done. This is basically all you need to send text messages with TextMagic.
Thanks for sharing. Also, MsgClub allows you to write your own Bulk SMS API PHP codes as per the requirements which makes coding even more personalized for the user.
ReplyDeletephp sms gateway integration
Get ready SMS PHP API or Bulk SMS API PHP Gateway Integration Source Code/Script to Integrate into your website, software or web application. MsgClub PHP APIs helps to send verification code or OTP, Transactional & Promotional SMS from your PHP based application automatically.
ReplyDeleteThis comprehensive guide provides a step-by-step approach to integrating SMS functionality into your PHP applications using TextMagic. From setting up your TextMagic account to crafting and sending your first SMS message, this tutorial covers everything you need to know. Perfect for developers looking to enhance their applications with reliable SMS capabilities, the guide includes code examples, best practices, and troubleshooting tips to ensure a smooth integration process. Whether you're a beginner or an experienced developer, you'll find this guide invaluable for leveraging TextMagic's powerful SMS API with PHP.
ReplyDeleteAlso Checkout: SMS Service Provider