Username: Password:

Forgot password? Sign up


Sign up

Receive 5 free credits.
Easy to try, simple to use.


register

Test Network

+


PHP code sample

Simplest case - sending a single message:

<?php
	$username = 'your_username';
	$password = 'your_password';
	$msisdn = '44123123123';
	$message = 'This is a test SMS';

	$url = 'http://bulksms.2way.co.za/eapi/submission/send_sms/2/2.0';
	$port = 80;
	/*
	* We recommend that you use port 5567 instead of port 80, but your
	* firewall will probably block access to this port (see FAQ for more
	* details):
	* $port = 5567;
	*/

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt ($ch, CURLOPT_PORT, $port);
	curl_setopt ($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

	$post_body = '';

	$post_fields = array(
		username => $username,
		password => $password,
		message => $message,
		msisdn => $msisdn
	);

	foreach($post_fields as $key=>$value) {
		$post_body .= urlencode($key).'='.urlencode($value).'&';
	}
	$post_body = rtrim($post_body,'&');

	# Do not supply $post_fields directly as an argument to CURLOPT_POSTFIELDS,
	# despite what the PHP documentation suggests: cUrl will turn it into in a
	# multipart formpost, which is not supported:
	curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_body);
	$response_string = curl_exec($ch);
	$curl_info = curl_getinfo($ch);

	if ($response_string == FALSE) {
		print "cURL error: ".curl_error($ch)."\n";
	} elseif ($curl_info['http_code'] != 200) {
		print "Error: non-200 HTTP status code: ".$curl_info['http_code']."\n";
	}
	else {
		print "Response from server:$response_string\n";
		$result = split('\|', $response_string);
		if (count($result) != 3) {
			print "Error: could not parse valid return data from server.\n".count($result);
		} else {
			if ($result[0] == '0') {
				print "Message sent - batch ID $result[2]\n";
			}
			else {
				print "Error sending: status code [$result[0]] description [$result[1]]\n";
			}
		}
	}
	curl_close($ch);
?>