Sending SMS with PHP and TextMagic: An A to Z guide

by Jean.

Over the years, Short message service (SMS) has become a very important way of communication, and many businesses are looking for easy ways to send automated text messages to their customers. In this tutorial, I’m going to show you how you can send SMS using PHP and a third party service called TextMagic. Its very easy to do!

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. Go here 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 to this page and click on the “Download” button to get the API files. Extract the 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.


$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.
By the way, if anyone ever heard of a free and reliable service to send SMS, please let me know in a comment!

CWC Special Deal!

Get one year of quality hosting + domain from A Small Orange for only $40 with our exclusive deal!

Featured WordPress Theme

Caliber - Responsive WordPress Theme

  • Try for $0.01 per text option and even click-to-call tools.

  • TextMagic looks really good. I will give it a try… sending some test SMS using the free 10 SMS credits. Thanks for sharing this great service!

  • Very nice!

  • Thanks a lot, I was looking for something like this and I am going to do this for my wordpress blog now.

  • I’m sms addict lol :p

  • is this TextMagic work in other country? like Philippines or it only works in US based country?

  • I was looking for something like this. Thank you.
    You guys really rocks for us. 🙂

  • Mike T have global connectivity and provide free credits also. I used their messenger product a while ago for a project and it was like threaded webmail but with texting…. pretty cool!

  • amit

    is there any free api available for sms sending..

    • Mittul Chauhan

      no amit .. i do not think so ..