Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- @description A function to receive SMS from FreeSMS4Us.com. It returns an array with all SMS received.
- @author Jefrey S. Santos <jefreysobreira[at]gmail[dot]com>
- @note There's no way to send SMS by PHP (by that website) because of the damn (but creative) captcha.
- */
- function freesms4us_get($number) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "http://freesms4us.com/reply.php");
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, "nomer=$number");
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
- curl_setopt($ch, CURLOPT_TIMEOUT, 60);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $store = curl_exec($ch);
- $store = strip_tags($store);
- $store = explode("\n", $store);
- $store = array_map("trim", $store);
- $msgs = array();
- foreach($store as $line) {
- $pattern = "/^SMS no:\-[0-9]*\. [ ]{4}(.*) \)(.*)$/";
- if(preg_match($pattern, $line)) {
- $res = array();
- preg_match_all($pattern, $line, $res);
- if(count($res)) {
- $msgs[] = $res[2][0];
- }
- }
- }
- return $msgs;
- }
- // Example of use:
- $number = "000000000000"; // no need +62, just start with 0
- $sms = freesms4us_get($number);
- foreach($sms as $message) {
- echo $message."<br/>"; // display the message
- }
- // Example #2: Multiple numbers
- $numbers = array(
- "John Doe" => "000000000000",
- "Jane Roe" => "000000000000" // no comma after the last number
- );
- foreach($numbers as $number) { // loop for numbers
- echo "SMS from ".$number;
- $sms = freesms4us_get($number);
- echo "<ul>";
- foreach($sms as $message) { // loop for messages
- echo "<li>";
- echo $message;
- echo "</li>";
- }
- echo "</ul>";
- echo "<hr/>";
- }
Add Comment
Please, Sign In to add comment