2 ////////////////////////////////////////////////////////////////////
6 // require_once("sms_tm4b.php");
7 // $sms = new sms( "user", "pass" );
8 // $sms->send("123456789","sender","message");
12 // Created by: Avasiloaei Dorin
13 // Modified by: Larry Lart
14 ////////////////////////////////////////////////////////////////////
21 function sms( $strUser, $strPass )
23 $this->username
= $strUser;
24 $this->password
= $strPass;
30 * @return string response
33 function send($phoneNo, $sender, $message)
35 /* Prepare the server request */
37 $request .= "username=".urlencode($this->username
);
38 $request .= "&password=".urlencode($this->password
);
39 $request .= "&revision=2.0";
40 $request .= "&type=broadcast";
41 $request .= "&msg=".urlencode($message);
42 $request .= "&to=".urlencode($phoneNo);
44 // larry :: default if not defined - TODO replace
46 $request .= "&from=BosmanGGZ";
48 $request .= "&from=".urlencode($sender);
50 $request .= "&route=GD02";
53 * Send the request to the server
54 * @TODO make sure the request was sent
57 $response = $this->_send($request);
59 echo "DEBUG :SMS ENGINE: sms sent with code =".$response." for req= ".$request."\n";
62 * Return the server response
63 * @TODO parse the server response
72 * @return string response
74 function _send($request)
76 if(extension_loaded('curl'))
79 * cURL extension is installed
80 * call the method that sends the sms through cURL
83 $response = $this->_send_curl($request);
85 elseif(!extension_loaded('sockets'))
88 * Sockets extension is installed
89 * call the method that sends the sms through sockets
92 $response = $this->_send_sock($request);
97 * The required extensions are not installed
98 * call the method that sends the sms using file_get_contents
101 $response = file_get_contents("https://www.tm4b.com/client/api/http.php?".$request);
104 /* Return the server response */
109 * Send SMS through cURL
111 * @return string response
114 function _send_curl($request)
116 /* Initiate a cURL session */
119 /* Set cURL variables */
120 curl_setopt($ch, CURLOPT_URL
, "https://www.tm4b.com/client/api/http.php");
121 curl_setopt($ch, CURLOPT_RETURNTRANSFER
,1);
122 curl_setopt($ch, CURLOPT_POST
, 1);
123 curl_setopt($ch, CURLOPT_POSTFIELDS
, $request);
124 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER
, 0);
126 /* Send the request through cURL */
127 $response = curl_exec($ch);
129 /* End the cURL session */
132 /* Return the server response */
137 * Send SMS using the sockets extension
139 * @return string response
141 function _send_sock($request)
143 /* Prepare the HTTP headers */
144 $http_header = "POST /client/api/http.php HTTP/1.1\r\n";
145 $http_header .= "Host: tm4b.com\r\n";
146 $http_header .= "User-Agent: HTTP/1.1\r\n";
147 $http_header .= "Content-Type: application/x-www-form-urlencoded\r\n";
148 $http_header .= "Content-Length: ".strlen($request)."\r\n";
149 $http_header .= "Connection: close\r\n\r\n";
150 $http_header .= $request."\r\n";
152 /* Set the host that we are connecting to and the port number */
153 $host = "ssl://tm4b.com";
156 /* Connect to the TM4B server */
157 $out = @fsockopen
($host, $port, $errno, $errstr);
159 /* Make sure that the connection succeded */
162 /* Send the request */
163 fputs($out, $http_header);
165 /* Get the response */
166 while(!feof($out)) $result[] = fgets($out);
168 /* Terminate the connection */
171 /* Get the response from the returned string */
172 $response = $result[9];