The easiest way to send SMS using PHP via API, all countries support, also send SMS in WordPress sites, example with code.

How to Send SMS in PHP

Using Textlocal API you can send SMS in PHP or in WordPress sites. You will learn how to send, with examples.

Send SMS

Go to Textlocal, register a new account and create a new API Key, read this post to learn how to get your API Key, anyway use this code to send your SMS:

<?php

    /* By Qassim Hassan - wp-time.com */

    $data = array(
                'apiKey'  => 'xxxxxx', // Enter your API Key
                'numbers' => trim(447123456789, '+'), // Enter number in international format (i.e. 447123456789), without "+"
                'sender'  => urlencode('WP Time'), // Enter sender name
                'message' => rawurlencode('This is an example to send SMS via API using PHP.'), // Enter your SMS message
                'test'    => false // Set to TRUE, if you want Test Mode
            );

    $ch = curl_init('http://api.txtlocal.com/send/');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);

    echo $response;

?>

If you want Test Mode, set ‘test’ to TRUE:


'test' => TRUE

You can send your SMS to more than 1 mobile, use Array():


'numbers' => array(447123456789, 447987456123, 4476547891),

Anyway the result is:

sms via api using php

For WordPress

An example for WordPress:


/* By Qassim Hassan - wp-time.com */

$data = array(
            'apiKey'  => 'xxxxxx', // Enter your API Key
            'numbers' => trim(447123456789, '+'),
            'sender'  => urlencode('WP Time'),
            'message' => rawurlencode('I Like WordPress!'),
            'test'    => false
        );

$post_args = array('body' => $data);

$api = wp_remote_post('http://api.txtlocal.com/send/', $post_args);

$result = wp_remote_retrieve_body($api);

$json = json_decode($result, true);

print_r($json);

Resources

Read Textlocal API documentation. Check SMS plugin for WordPress.