3 ////////////////////////////////////////////////////////////////////
7 // require_once("sms_tm4b.php");
8 // $sms = new sms( "user", "pass" );
9 // $sms->send("123456789","sender","message");
13 // Created by: Avasiloaei Dorin
14 // Modified by: Larry Lart
15 ////////////////////////////////////////////////////////////////////
22 function __construct($strUser, $strPass)
24 $this->username
= $strUser;
25 $this->password
= $strPass;
31 * @return string response
34 function send($phoneNo, $sender, $message)
36 /* Prepare the server request */
38 $request .= "username=" . urlencode($this->username
);
39 $request .= "&password=" . urlencode($this->password
);
40 $request .= "&revision=2.0";
41 $request .= "&type=broadcast";
42 $request .= "&msg=" . urlencode($message);
43 $request .= "&to=" . urlencode($phoneNo);
45 // larry :: default if not defined - TODO replace
47 $request .= "&from=BosmanGGZ";
49 $request .= "&from=" . urlencode($sender);
52 $request .= "&route=GD02";
55 * Send the request to the server
56 * @TODO make sure the request was sent
59 $response = $this->_send($request);
61 echo "DEBUG :SMS ENGINE: sms sent with code =" . text($response) . " for req= " . text($request) . "\n";
64 * Return the server response
65 * @TODO parse the server response
74 * @return string response
76 function _send($request)
78 if (extension_loaded('curl')) {
80 * cURL extension is installed
81 * call the method that sends the sms through cURL
84 $response = $this->_send_curl($request);
85 } elseif (!extension_loaded('sockets')) {
87 * Sockets extension is installed
88 * call the method that sends the sms through sockets
91 $response = $this->_send_sock($request);
94 * The required extensions are not installed
95 * call the method that sends the sms using file_get_contents
98 $response = file_get_contents("https://www.tm4b.com/client/api/http.php?" . $request);
101 /* Return the server response */
106 * Send SMS through cURL
108 * @return string response
111 function _send_curl($request)
113 /* Initiate a cURL session */
116 /* Set cURL variables */
117 curl_setopt($ch, CURLOPT_URL
, "https://www.tm4b.com/client/api/http.php");
118 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, 1);
119 curl_setopt($ch, CURLOPT_POST
, 1);
120 curl_setopt($ch, CURLOPT_POSTFIELDS
, $request);
121 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER
, 0);
123 /* Send the request through cURL */
124 $response = curl_exec($ch);
126 /* End the cURL session */
129 /* Return the server response */
134 * Send SMS using the sockets extension
136 * @return string response
138 function _send_sock($request)
140 /* Prepare the HTTP headers */
141 $http_header = "POST /client/api/http.php HTTP/1.1\r\n";
142 $http_header .= "Host: tm4b.com\r\n";
143 $http_header .= "User-Agent: HTTP/1.1\r\n";
144 $http_header .= "Content-Type: application/x-www-form-urlencoded\r\n";
145 $http_header .= "Content-Length: " . strlen($request) . "\r\n";
146 $http_header .= "Connection: close\r\n\r\n";
147 $http_header .= $request . "\r\n";
149 /* Set the host that we are connecting to and the port number */
150 $host = "ssl://tm4b.com";
153 /* Connect to the TM4B server */
154 $out = @fsockopen
($host, $port, $errno, $errstr);
156 /* Make sure that the connection succeded */
158 /* Send the request */
159 fputs($out, $http_header);
161 /* Get the response */
162 while (!feof($out)) {
163 $result[] = fgets($out);
166 /* Terminate the connection */
170 /* Get the response from the returned string */
171 $response = $result[9];