<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Send SMS from your web page</title>
</head>
<body>
<?php
$footer = 'Your footer text';
$maxSizeSms = 160 - strlen($footer);
DEFINE('API_USER', 'ts_ravie');
DEFINE('API_PWD', 'rav@34');
DEFINE('API_receipt', 'Yes');
DEFINE('API_sender', 'Ravience');
// check if form has been "posted"
if( isset($_GET['mobile']) && isset($_GET['sms']) ){
// phone number and message (message + footer)
preg_match_all('/[\d]{11}/', $_GET['mobile'], $mobile);
$sms = urlencode(substr($_GET['sms'], 0, $maxSizeSms).$footer);
// URL for sending the SMS
$apiCallUrl = 'http://122.169.193.83:8888/?';
$apiCallUrl .= 'User='.API_USER.'&Password='.API_PWD.'&ReceiptRequested='.API_receipt.'&sender='.API_sender;
$apiCallUrl .= '&PhoneNumber='.$_GET['mobile'].'&Text='.$sms;
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $apiCallUrl);
curl_setopt($curlHandle, CURLOPT_HEADER, 0);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlHandle, CURLOPT_POST, 1);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $data);
curl_setopt($curlHandle, CURLOPT_TIMEOUT, 15);
$content = curl_exec($curlHandle); // Make the call for sending the SMS
curl_close($curlHandle); // Close the connection to Clickatell
if( preg_match('/^ID:/', $content) ){
echo '<h2>Message have been sent</h2>';
}else{
echo '<h2>Error sending message</h2>';
}
}
?>
<form method="get" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
Phone number <br />
<input type="text" name="mobile" size="20" maxlength="12" value="" />
<br />
Message <br />
<input type="text" name="sms" size="30" maxlength="<?php echo $maxSizeSms ?>" value="" />
<br />
<input type="submit" value="Send SMS" />
</form>
</body>
</html>