Jump to content
xisto Community
alex198555

Sms And Php ????

Recommended Posts

Hi! I would like to enable the sms service on my web-site. I need some free sms engine which can be run on my web-space and which can be used to send messages to web-site's users? Is it possible?

Share this post


Link to post
Share on other sites

I did a little research, and found something on this. Basically, you can send sms messages through PHP through a gateway.

Here's the HTML code:

   <table border=0>
<tr>
<td>Recipient</td>
<td><input type='text' name='recipient'></td>
</tr>
<tr>
<td>Message</td>
<td><textarea rows=4 cols=40 name='message'></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type=submit name=submit value=Send></td>
</tr>
</table>
</form>
</body>
</html>
linenums:0'><html> <body> <h1>My SMS form</h1> <form method=post action='sendsms.php'> <table border=0> <tr> <td>Recipient</td> <td><input type='text' name='recipient'></td> </tr> <tr> <td>Message</td> <td><textarea rows=4 cols=40 name='message'></textarea></td> </tr> <tr> <td> </td> <td><input type=submit name=submit value=Send></td> </tr> </table> </form> </body></html>
And here's the PHP code:
<?php######################################################### Login information for the SMS Gateway########################################################$ozeki_user = "admin";$ozeki_password = "abc123";$ozeki_url = "http://127.0.0.1:9501/api?";######################################################### Functions used to send the SMS message########################################################function httpRequest($url){    $pattern = "/http...([0-9a-zA-Z-.]*).([0-9]*).(.*)/";    preg_match($pattern,$url,$args);    $in = "";    $fp = fsockopen("$args[1]", $args[2], $errno, $errstr, 30);    if (!$fp) {       return("$errstr ($errno)");    } else {        $out = "GET /$args[3] HTTP/1.1\r\n";        $out .= "Host: $args[1]:$args[2]\r\n";        $out .= "User-agent: Ozeki PHP client\r\n";        $out .= "Accept: */*\r\n";        $out .= "Connection: Close\r\n\r\n";        fwrite($fp, $out);        while (!feof($fp)) {           $in.=fgets($fp, 128);        }    }    fclose($fp);    return($in);}function ozekiSend($phone, $msg, $debug=false){      global $ozeki_user,$ozeki_password,$ozeki_url;      $url = 'username='.$ozeki_user;      $url.= '&password='.$ozeki_password;      $url.= '&action=sendmessage';      $url.= '&messagetype=SMS:TEXT';      $url.= '&recipient='.urlencode($phone);      $url.= '&messagedata='.urlencode($msg);      $urltouse =  $ozeki_url.$url;      if ($debug) { echo "Request: <br>$urltouse<br><br>"; }      //Open the URL to send the message      $response = httpRequest($urltouse);      if ($debug) {           echo "Response: <br><pre>".           str_replace(array("<",">"),array("<",">"),$response).           "</pre><br>"; }      return($response);}######################################################### GET data from sendsms.html########################################################$phonenum = $_POST['recipient'];$message = $_POST['message'];$debug = true;ozekiSend($phonenum,$message,$debug);?>

Note; I didn't write the code, I found it on a website which discusses this topic.

The one that I found is called Ozeki NG SMS Gateway.

You can find more information and download it here:

http://www.ozekisms.com/index.php?owpn=327

Share this post


Link to post
Share on other sites

i am not quite sure of what you want exactly, but i will give you some options:

you can send email to others in php using mail() function, these links show you how to write a simple email script using mail() function

http://www.dreamincode.net/forums/topic/10130-send-emails-using-php-basic/
http://php.about.com/od/advancedphp/ss/mail.htm

this link show you how to send text email, HTML email or attachment
http://forums.xisto.com/no_longer_exists/

or you can send email using the mailing list, check this link
http://forums.xisto.com/no_longer_exists/

good luck.

Share this post


Link to post
Share on other sites

Has anyone been able to test and see if that script actually works and to what countries the gateway is open to? If anyone has tried the script and it does function please let us know. I think that would be a handy bit of script to have lying around.

Share this post


Link to post
Share on other sites

I think that this "Ozeki NG SMS Gateway" is offering the service for a huge amount of money !!
You can find other SMS service providers with cheaper offers , but the script will not suit them , so i'm going to give you a simple SMS script , that you can use to send/receive SMS from a web interface , but before that , let's learn some about SMS messaging :

What's MO : MO for Mobile Originated ; A mobile user sends an SMS to our application.
What's MT : MT for Mobile Terminated ; Our application sends SMS to a user mobile.

Before you can receive SMS , you need to have a number in wich you are going to receive SMS sent by users to it.
You can use the AT Commands , with a mobile phone or a GSM modem , but it's hard to configure , and you won't be able to receive large amounts of SMS per minute !

You can rent a short number from an SMS service provider , generally the short number will be shared , so you have to use a keyword , so that all SMS sent to this short number and starting with your keyword , will be received by your account .
I'm going to use tm4b SMS service with a french short number , you can use whatever you like !

The MO query :

from: the mobile number from wich the SMS was sent.
Msg: the text of the SMS.
To:the short number to wich the SMS was sent.
You can find a large amount of parameters that you can use to develop more sophisticated applications

We are going to use Yahoo! Weather API , but you can use whatever you want ,'Yahoo!traffic ....etc' .
Here is the script

	  <?php  	      	  echo "<pre>";   	  print_r($_GET);   	      	  /*Extraction of the keywords   	  -----------------------------------------------------------------*/   	  $Keywords = explode(" ", $_GET['msg']);  	     	  /*Ask the Yahoo! Weather API  	  -----------------------------------------------------------------*/ 	  //Identification of the Location ID  	  switch(strtoupper($Keywords[1]))	  { 	  case "BORDEAUX": $LocationID = "FRXX0016";	  case "LYON": $LocationID = "FRXX0055";	  case "PARIS": $LocationID = "FRXX0076";  	  } 	   	  //If the town is ok, we call Yahoo!	  if($LocationID)	  {	  //Url Creation	  $YahooURI = "http://weather.yahooapis.com/forecastrss?p=$LocationID&u=c";	   	  //Call Yahoo Weather API 	  $YahooResponse = file_get_contents($YahooURI); #If allow_url_fopen is off in your php.ini, you'll have to use cUrl	  }	   	  //If we have an answer, we will analyse it	  if($YahooResponse)	  {	  preg_match_all("#<description>(.+)<\/description>#Uis", $YahooResponse, $Matches);	  $Forecast = trim(strip_tags($Matches[1][1]));	  $Forecast = str_replace("\t", "", $Forecast);	  while(strstr($Forecast, "\n ")) $Forecast = str_replace("\n ", "\n", $Forecast);	  $ForecastArray = explode("\n\n", $Forecast);	  $Forecast = "Weather for $Keywords[1]\n".$ForecastArray[0];	  }	   	  /* Answer SMS 	  -----------------------------------------------------------------*/	  if(!$LocationID)	  {	  if($Keywords[1]) $OurResponse = "Sorry, we don't support $Keywords[1]! For supported locations, visit http://weather.yahoo.com/regional/FRXX.html.";	  else $OurResponse = "It looks like you forgot to include a location. Please try again with a location.";	  }	  elseif($Forecast) $OurResponse = $Forecast;	  else $OurResponse = "Sorry, but the service is down. Please try again later.";	   	   	  /* Sending the SMS	  -----------------------------------------------------------------*/	  //Query preparation. Details @ http://forums.xisto.com/no_longer_exists/	  $Param['username'] = 'username';	  $Param['password'] = 'password';	  $Param['type'] = 'broadcast';	  $Param['msg'] = $OurResponse;	  $Param['to'] = $_GET['from'];	  $Param['from'] = $_GET['to'];	  $Param['route'] = 'GD01';	  $Param['version'] = '2.1';	  foreach($Param as $Key => $Value) $Request .= $Key.'='.urlencode($Value)."&";	   	  //Calling the SMS API	  $SP_Response = file_get_contents("http://http://www.tm4b.com/client/api/http.php?$Request;;	   	  //Recover send id 	  if(!strstr($SP_Response, "broadcastID")) echo $SR_Response;	  else	  {	  preg_match("/<broadcastID>([^<]*)<\/broadcastID>/i", $SP_Response, $Matches);	  echo "BroadcastID = $Matches[1]";	  }	  ?>

You can try it , an improve it , since there is a lot of work to do with the keywords development !

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.