<?
session_start();
/**
@desc Include all the country codes you wish to allow here
**/
$allowed = array
(
"44",
"32"
);
/**
@desc Maximum amount of characters per message
**/
define("MAX_LENGTH", 160 );
/**
@desc Set a max message per hour limit
**/
define("MAX_MESSAGES", 5 );
/**
@desc This is where we start to process the forms request
**/
if( $_REQUEST['ajax'] ):
if( $_COOKIE['sent'] > MAX_MESSAGES ) :
printf("You have reached your maximum amount of messages [ %d ] please come back in one hour", MAX_MESSAGES );
elseif( $_REQUEST['to'] == "" or $_REQUEST['ajax'] == "") :
print("Both fields are required");
elseif( @strlen( $_REQUEST['text'] ) > MAX_LENGTH ):
printf( "Your message is too long, please shorten it to %d", MAX_LENGTH );
elseif( preg_match('#[^0-9]+#', $_REQUEST['to'] ) ) :
printf( "%s is not a valid phone number, please use ONLY digits", $_REQUEST['to'] );
elseif( !@in_array( substr( preg_replace('#\^+#', '', $_REQUEST['to'] ), 0, 2 ), $allowed ) ):
print( "Messages to that country are not supported") ;
else:
setcookie( 'sent', $_SESSION['requests']++, time()+3600 );
exec( sprintf("sms.exe -receiver:+%s -text:\"%s\"", $_REQUEST['to'], $_REQUEST['text'] ) );
printf("Message queued for delivery to %s", $_REQUEST['to'] );
endif;
else:
?>
<html>
<head>
<title>Page Title</title>
<style type="text/css">
body{ }
td { vertical-align:top; }
div#message{ color:#FF0000; font-weight:bold; }
div#container{ border: 1px solid black; width:500px; }
.textarea, .input{ width:100%; }
.submit{ border:0px; background-color:blue; color:white; width:100%; font-weight:bold; }
</style>
<script language="javascript">
function sendSMS( to, text )
{
var xmlhttp=false;
document.getElementById('sending').innerHTML = '<center><img src=sending.gif border=0/></center>';
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E)
{
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try
{
xmlhttp = new XMLHttpRequest();
}
catch (e)
{
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try
{
xmlhttp = window.createRequest();
}
catch (e)
{
xmlhttp=false;
}
}
xmlhttp.open( "GET", "<?=$_SERVER['PHP_SELF']; ?>?ajax=1&to=" + encodeURI( to ) + "&text=" + encodeURI( text ), true );
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4)
{
document.getElementById('sending').innerHTML = '<input type="button" class="submit" value="Send Message" onclick="sendSMS( document.getElementById(\'to\').value, document.getElementById(\'text\').value );" />';
document.getElementById('message').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null)
}
</script>
</head>
<body>
<form action="" method="post">
<center>
<div id="container">
<table width="100%" border="0">
<tr>
<td><div id="message"></div></td>
</tr>
<tr>
<td><input type="text" name="number" class="input" id="to"/></td>
</tr>
<tr>
<td><textarea name="message" cols="30" rows="5" class="textarea" id="text"></textarea></td>
</tr>
<tr>
<td colspan="2">
<span id="sending">
<input
type="button"
class="submit"
value="Send Message"
onclick="sendSMS( document.getElementById('to').value, document.getElementById('text').value );"
/>
</span>
</td>
</tr>
</table>
</div>
</center>
</form>
</body>
</html>
<?
endif;
?>