Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

To send an SMS with our PHP wrapper, download and unzip the wrapper from here, then copy the TMRestClient.php file into your class path, or the folder you are running the code from.

 

Now put the following code somewhere in a PHP file and execute it to send an SMS – don't forget to substitute your own API username and password and a real mobile number to send to!

Code Block
themeRDark
languagephp
linenumberstrue
include_once('TMRestClient.php');
$tmClient = new TMRestClient('myAPIusername', 'myAPIpassword', 'production');
$sent = false;
try {
	$sent = $tmClient->sendSMS('My message', '447000000000', 'Sender');
} catch (Exception $ex) {
	$errors = $tmClient->getLastErrors();
}
if ($sent)
	echo "Message sent with ID " . $sent['message_id'];
else
	foreach($errors as $errorcode => $errormsg)
		echo "Error encountered with code $errorcode: $errormsg\n";

For more details about the additional arguments the sendSMS function can take, and other important considerations of sending messages, see send sms.

 

In a real situation you must decide how to deal with any errors, we also recommend logging all errors. See the Handling errors section below for more details.

Tip

You can find your API username and password (which may be different to your web interface username/password) via your account: https://messagebox.textmarketer.co.uk/#!accountsettings/


If you don't have an account, you can set one up for free at
www.textmarketer.co.uk.