"Awaiting result" # 2 => "Sending message.." # 3 => "Sending message..." # 4 => "Delivered" # 5 => "Error with message", # 6 => "User cancelled message delivery", # 7 => "Error delivering message", # 8 => "OK", # 9 => "Routing error", $username = ""; # your login $password = ""; # your password $mobilenums= array("msg99"=>"+00-00-000-000-3","msg"=>"+00-00-000-000-4"); # recipient numbers w/o errors #$mobilenums= array("msg99"=>"0003","msg"=>"+00-00-000-000-4"); # recipient numbers w/ error in ph# $messages = array("msg99"=>"message text here","msg"=>"another message text here"); #$message = "single text"; #$delays = array("msg99"=>10,"msg"=>20); #$delay = 5; $host = ""; $path = "/api/sms.asmx"; function post_request($host, $path, $params, $type = "application/x-www-form-urlencoded" ) { $http_header = array(); $result = ""; $fp = fsockopen($host, 80, $errno, $errstr, 30); if(!$fp) return array ("", ""); else { if(is_array($params)) { foreach($params as $k => $v) $params[$k] = urlencode($k)."=".urlencode($v); $params = join("&",$params); } $req = "POST ".$path." HTTP/1.0\r\n"; $req.= "Host: ".$host."\r\n"; $req.= "User-Agent: Mozilla/4.5 [en]\r\n"; $req.= "Content-Type: ".$type."\r\n"; $req.= "Content-Length: ".strlen($params)."\r\n"; $req.= "\r\n"; $req.= $params."\r\n\r\n"; fputs($fp, $req); $header_passed = 0; $http_header["ERROR"] = chop(fgets($fp,4096)); while(!feof($fp)) { $line = fgets($fp,4096); $tlin = trim($line); if(!$header_passed && !$tlin) $header_passed = 1; elseif(!$header_passed) { $header_line = explode(": ", $line, 2); $http_header[strtolower($header_line[0])] = chop($header_line[1]); continue; } else $result .= $line; } fclose ($fp); } return array($http_header, $result); } print "
";
print "

Step #0. Verify your data.

"; print "Username : ".$username."\n"; if($message) print "Message : ".$message."\n"; foreach($mobilenums as $id => $mobilenum) { print "Id : ".$id."\n"; print "Mobile# : ".$mobilenum."\n"; if(!$message) print "Message : ".$messages[$id]."\n"; } print "

Step #1. Check your balance!

"; $params = array( "action" => "GetCreditBalance", "username" => $username, "password" => $password, ); $result = post_request($host, $path, $params); preg_match("/]*>(.*)<\/string>/i",$result[1],$out); print "RawResponse: ".htmlentities($result[1])."\n"; print "Response : ".$out[1]."\n"; print "

Step #2. Ready? Put a message on air!

"; $params = array( "action" => "SendMessage", "username" => $username, "password" => $password, ); if($message) $params["messageText"] = $message; if($delay) $params["delay"] = $delay; foreach($mobilenums as $id => $mobilenum) { $params["mobileNumber[".$id."]"] = $mobilenum; if(!$message) $params["messageText[".$id."]"] = $messages[$id]; if(!$delay && !empty($delays)) $params["delay[".$id."]"] = $delays[$id]; } $result = post_request($host, $path, $params); preg_match("/(OK|NOK)<\/status>/iU",$result[1],$ok); preg_match_all("/\s*(.*)<\/id>\s*(.*)<\/message><\/sms>/iU",$result[1],$out); print "Status: ".$ok[1]."\n"; print "RawResponse: ".htmlentities($result[1])."\n"; $messageids = array(); foreach($out[1] as $i => $id) { $messageids[$id] = $out[2][$i]; print "Response[".$id."]: ".$out[2][$i]."\n"; } print "

Step #3. Yeah! It's delivered!

"; $params = array( "action" => "GetMessageStatus", "username" => $username, "password" => $password, ); foreach($messageids as $id => $messageid) $params["messageId[".$id."]"] = $messageid; $result = post_request($host, $path, $params); preg_match_all("/\s*(.*)<\/id>\s*(.*)<\/code>\s*(.*)<\/message><\/sms>/iU",$result[1],$out); print "RawResponse: ".htmlentities($result[1])."\n"; foreach($out[1] as $i => $id) print "Response[".$id."] : ".$out[3][$i]." (Code:".$out[2][$i].")\n"; print "

Check #1. Wrong password.

"; $params = array( "action" => "GetCreditBalance", "username" => $username, "password" => $password."wrong", ); $result = post_request($host, $path, $params); preg_match("/]*>(.*)<\/string>/i",$result[1],$out); print "RawResponse: ".htmlentities($result[1])."\n"; print "Response : ".$out[1]."\n"; print "

Check #2. Wrong action.

"; $params = array( "action" => "GetSomethingInteresting", "username" => $username, "password" => $password, ); $result = post_request($host, $path, $params); preg_match("/]*>(.*)<\/string>/i",$result[1],$out); print "RawResponse: ".htmlentities($result[1])."\n"; print "Response : ".$out[1]."\n"; $soap_start = ' '; $soap_end = ' '; print "

SOAP. SendMessage.

"; $xml = ' '.$username.' '.$password.''; if($message) $xml .= ''.$message.''; if($delay) $xml .= ''.$delay.''; foreach($mobilenums as $id => $mobilenum) { $xml .= ''; $xml .= ''.$id.''; $xml .= ''.$mobilenum.''; if(!$message) $xml .= ''.$messages[$id].''; if(!$delay && !empty($delays)) $xml .= ''.$delays[$id].''; $xml .= ''; } $xml .= ''; $result = post_request($host, $path, $soap_start.$xml.$soap_end,'text/xml'); preg_match("/(OK|NOK)<\/status>/iU",$result[1],$ok); preg_match_all("/\s*(.*)<\/id>\s*(.*)<\/message><\/sms>/iU",$result[1],$out); print "Status: ".$ok[1]."\n"; print "RawResponse: ".htmlentities($result[1])."\n"; $messageids = array(); foreach($out[1] as $i => $id) { $messageids[$id] = $out[2][$i]; print "Response[".$id."]: ".$out[2][$i]."\n"; } print "

SOAP. GetMessageStatus.

"; $xml = ' '.$username.' '.$password.''; foreach($messageids as $id => $messageid) $xml .= ''.$id.''.$messageid.''; $xml .=''; $result = post_request($host, $path, $soap_start.$xml.$soap_end,'text/xml'); preg_match_all("/\s*(.*)<\/id>\s*(.*)<\/code>\s*(.*)<\/message><\/sms>/iU",$result[1],$out); print "RawResponse: ".htmlentities($result[1])."\n"; foreach($out[1] as $i => $id) print "Response[".$id."] : ".$out[3][$i]." (Code:".$out[2][$i].")\n"; ?>