Jump to content

Search the Community

Showing results for tags 'sms'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (Dreamweaver, Zend, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 6 results

  1. Hello, so I have input form for feedback with php mail send but i also want to send a sms message to user. This is html: <div class="fs-form-wrap" id="fs-form-wrap"> <form id="form" class="fs-form fs-form-full" action="#" method="post" autocomplete="off"> <ol class="fs-fields"> <li> <label class="fs-field-label fs-anim-upper" for=Name?</label> <input class="fs-anim-lower" id="q1" name="q1" type="text" placeholder="Name" required/> </li> <li> <label class="fs-field-label fs-anim-upper" for="q2" data-info="Vaild eamil....?</label> <input class="fs-anim-lower" id="q2" name="q2" type="email" placeholder="email@email.com" required/> </li> <li> <label class="fs-field-label fs-anim-upper" for="q3" data-info="Valid phone number">Phone number...?</label> <input onkeypress='return event.charCode >= 48 && event.charCode <= 57' class="fs-anim-lower" id="q3" name="q3" type="text" maxlength="10" placeholder="09x-xxx-xxxx" required/> </li> <li> <label class="fs-field-label fs-anim-upper" for="q4" data-info="What do you think about our servise?">Feedback</label> <textarea class="fs-anim-lower" id="q4" name="q4" placeholder="Feedback.."></textarea> </li> </ol><!-- /fs-fields --> <button class="fs-submit" type="submit" name="submit" id="send" >Send</button> </form> </div> This is php mail: <?php if(isset($_POST["submit"])){ //Checking for blank Fields.. if($_POST["q1"]==""||$_POST["q2"]==""||$_POST["q3"]==""||$_POST["q4"]==""){ echo "Fill everything.."; }else{ // Check if the "Sender's Email" input field is filled out $email=$_POST['q2']; // Sanitize e-mail address $email =filter_var($email, FILTER_SANITIZE_EMAIL); // Validate e-mail address $email= filter_var($email, FILTER_VALIDATE_EMAIL); if (!$email){ echo "Invalid Sender's Email"; } else{ $subject = $_POST['q3']; $message = 'Name: ' . $_POST['q1'] . ' Email: ' . $_POST['q2'] . ' Phone Number: ' . $_POST['q3'] . ' Feedback: ' . $_POST['q4']; $headers = 'From:'. $email . "\r\n"; // Sender's Email // message lines should not exceed 70 characters (PHP rule), so wrap it $message = wordwrap($message, 70); // Send mail by PHP Mail Function mail("myemail@mydomain.com", $subject, $message, $headers); echo "Thank you for feedback"; } } } ?> I have public sms getaway on my computer so when user input his phone script make link like this "http://mysmsgetaway.com?PhoneNumber=user-phone-number&Text=message-from-us" and it goes to my getaway.. Thank you
  2. how can we send message to other mobile numbers using our website setup..? please help..?
  3. hello, i am new to php programming.. i need to execute this url in my send sms.php file.. i tried curl method but failed.. API URL is , sample" http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=hidden&password=hidden&sendername=iZycon&mobileno=8289947807 i just need to execute this url in my page... while replying plz include the php code..
  4. Hi! i'm currently have a problem using PHP in order to create a form that has the capability to send sms by using GSM modem, by the way, the modem that i'm using right now is Huawei E173 Broadband. I know there has been a lot of way to send sms using php but most of it is by using SMS Gateway, (eg like nowsms) To the problem, I wanna know how do i make this form below to send sms, now i've know that my modem is on COM6, so how do i integrate this form below here with GSM modem to send sms by using php+ So now i really need help here to teach me and guide me so that i can make php uses gsm modem to send sms. Thank you so much! Form: <html> <head> <title>FORM TEST</title> </head> <body> <form name="form1" action="" method="post"> Enter Mobile Number: <input type="text" name="text1"><br> Enter SMS: <textarea cols="10" rows="10" name="text2"></textarea><br> <input type="submit" name="submit1" value="Send SMS"> </form> </body> </html> To make this form integrae with code below to send sms example.php (my modem is using COM6) <?php include "php_serial.class.php"; // Let's start the class $serial = new phpSerial; // First we must specify the device. This works on both linux and windows (if // your linux serial device is /dev/ttyS0 for COM1, etc) $serial->deviceSet("COM6"); // Then we need to open it $serial->deviceOpen(); // To write into $serial->sendMessage("Hello !"); // Or to read from $read = $serial->readPort(); // If you want to change the configuration, the device must be closed $serial->deviceClose(); // We can change the baud rate $serial->confBaudRate(2400); // etc... ?> php_serial_class.php - to initialize send sms <?php define ("SERIAL_DEVICE_NOTSET", 0); define ("SERIAL_DEVICE_SET", 1); define ("SERIAL_DEVICE_OPENED", 2); /** * Serial port control class * * THIS PROGRAM COMES WITH ABSOLUTELY NO WARANTIES ! * USE IT AT YOUR OWN RISKS ! * * @author Rémy Sanchez <thenux@gmail.com> * @thanks Aurélien Derouineau for finding how to open serial ports with windows * @thanks Alec Avedisyan for help and testing with reading * @copyright under GPL 2 licence */ class phpSerial { var $_device = null; var $_windevice = null; var $_dHandle = null; var $_dState = SERIAL_DEVICE_NOTSET; var $_buffer = ""; var $_os = ""; /** * This var says if buffer should be flushed by sendMessage (true) or manualy (false) * * @var bool */ var $autoflush = true; /** * Constructor. Perform some checks about the OS and setserial * * @return phpSerial */ function phpSerial () { setlocale(LC_ALL, "en_US"); $sysname = php_uname(); if (substr($sysname, 0, 5) === "Linux") { $this->_os = "linux"; if($this->_exec("stty --version") === 0) { register_shutdown_function(array($this, "deviceClose")); } else { trigger_error("No stty availible, unable to run.", E_USER_ERROR); } } elseif(substr($sysname, 0, 7) === "Windows") { $this->_os = "windows"; register_shutdown_function(array($this, "deviceClose")); } else { trigger_error("Host OS is neither linux nor windows, unable tu run.", E_USER_ERROR); exit(); } } // // OPEN/CLOSE DEVICE SECTION -- {START} // /** * Device set function : used to set the device name/address. * -> linux : use the device address, like /dev/ttyS0 * -> windows : use the COMxx device name, like COM1 (can also be used * with linux) * * @param string $device the name of the device to be used * @return bool */ function deviceSet ($device) { if ($this->_dState !== SERIAL_DEVICE_OPENED) { if ($this->_os === "linux") { if (preg_match("@^COM(\d+):?$@i", $device, $matches)) { $device = "/dev/ttyS" . ($matches[1] - 1); } if ($this->_exec("stty -F " . $device) === 0) { $this->_device = $device; $this->_dState = SERIAL_DEVICE_SET; return true; } } elseif ($this->_os === "windows") { if (preg_match("@^COM(\d+):?$@i", $device, $matches) and $this->_exec(exec("mode " . $device)) === 0) { $this->_windevice = "COM" . $matches[1]; $this->_device = "\\.\com" . $matches[1]; $this->_dState = SERIAL_DEVICE_SET; return true; } } trigger_error("Specified serial port is not valid", E_USER_WARNING); return false; } else { trigger_error("You must close your device before to set an other one", E_USER_WARNING); return false; } } /** * Opens the device for reading and/or writing. * * @param string $mode Opening mode : same parameter as fopen() * @return bool */ function deviceOpen ($mode = "r+b") { if ($this->_dState === SERIAL_DEVICE_OPENED) { trigger_error("The device is already opened", E_USER_NOTICE); return true; } if ($this->_dState === SERIAL_DEVICE_NOTSET) { trigger_error("The device must be set before to be open", E_USER_WARNING); return false; } if (!preg_match("@^[raw]\+?b?$@", $mode)) { trigger_error("Invalid opening mode : ".$mode.". Use fopen() modes.", E_USER_WARNING); return false; } $this->_dHandle = @fopen($this->_device, $mode); if ($this->_dHandle !== false) { stream_set_blocking($this->_dHandle, 0); $this->_dState = SERIAL_DEVICE_OPENED; return true; } $this->_dHandle = null; trigger_error("Unable to open the device", E_USER_WARNING); return false; } /** * Closes the device * * @return bool */ function deviceClose () { if ($this->_dState !== SERIAL_DEVICE_OPENED) { return true; } if (fclose($this->_dHandle)) { $this->_dHandle = null; $this->_dState = SERIAL_DEVICE_SET; return true; } trigger_error("Unable to close the device", E_USER_ERROR); return false; } // // OPEN/CLOSE DEVICE SECTION -- {STOP} // // // CONFIGURE SECTION -- {START} // /** * Configure the Baud Rate * Possible rates : 110, 150, 300, 600, 1200, 2400, 4800, 9600, 38400, * 57600 and 115200. * * @param int $rate the rate to set the port in * @return bool */ function confBaudRate ($rate) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set the baud rate : the device is either not set or opened", E_USER_WARNING); return false; } $validBauds = array ( 110 => 11, 150 => 15, 300 => 30, 600 => 60, 1200 => 12, 2400 => 24, 4800 => 48, 9600 => 96, 19200 => 19, 38400 => 38400, 57600 => 57600, 115200 => 115200 ); if (isset($validBauds[$rate])) { if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " " . (int) $rate, $out); } elseif ($this->_os === "windows") { $ret = $this->_exec("mode " . $this->_windevice . " BAUD=" . $validBauds[$rate], $out); } else return false; if ($ret !== 0) { trigger_error ("Unable to set baud rate: " . $out[1], E_USER_WARNING); return false; } } } /** * Configure parity. * Modes : odd, even, none * * @param string $parity one of the modes * @return bool */ function confParity ($parity) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set parity : the device is either not set or opened", E_USER_WARNING); return false; } $args = array( "none" => "-parenb", "odd" => "parenb parodd", "even" => "parenb -parodd", ); if (!isset($args[$parity])) { trigger_error("Parity mode not supported", E_USER_WARNING); return false; } if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " " . $args[$parity], $out); } else { $ret = $this->_exec("mode " . $this->_windevice . " PARITY=" . $parity{0}, $out); } if ($ret === 0) { return true; } trigger_error("Unable to set parity : " . $out[1], E_USER_WARNING); return false; } /** * Sets the length of a character. * * @param int $int length of a character (5 <= length <= * @return bool */ function confCharacterLength ($int) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set length of a character : the device is either not set or opened", E_USER_WARNING); return false; } $int = (int) $int; if ($int < 5) $int = 5; elseif ($int > $int = 8; if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " cs" . $int, $out); } else { $ret = $this->_exec("mode " . $this->_windevice . " DATA=" . $int, $out); } if ($ret === 0) { return true; } trigger_error("Unable to set character length : " .$out[1], E_USER_WARNING); return false; } /** * Sets the length of stop bits. * * @param float $length the length of a stop bit. It must be either 1, * 1.5 or 2. 1.5 is not supported under linux and on some computers. * @return bool */ function confStopBits ($length) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set the length of a stop bit : the device is either not set or opened", E_USER_WARNING); return false; } if ($length != 1 and $length != 2 and $length != 1.5 and !($length == 1.5 and $this->_os === "linux")) { trigger_error("Specified stop bit length is invalid", E_USER_WARNING); return false; } if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " " . (($length == 1) ? "-" : "") . "cstopb", $out); } else { $ret = $this->_exec("mode " . $this->_windevice . " STOP=" . $length, $out); } if ($ret === 0) { return true; } trigger_error("Unable to set stop bit length : " . $out[1], E_USER_WARNING); return false; } /** * Configures the flow control * * @param string $mode Set the flow control mode. Availible modes : * -> "none" : no flow control * -> "rts/cts" : use RTS/CTS handshaking * -> "xon/xoff" : use XON/XOFF protocol * @return bool */ function confFlowControl ($mode) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set flow control mode : the device is either not set or opened", E_USER_WARNING); return false; } $linuxModes = array( "none" => "clocal -crtscts -ixon -ixoff", "rts/cts" => "-clocal crtscts -ixon -ixoff", "xon/xoff" => "-clocal -crtscts ixon ixoff" ); $windowsModes = array( "none" => "xon=off octs=off rts=on", "rts/cts" => "xon=off octs=on rts=hs", "xon/xoff" => "xon=on octs=off rts=on", ); if ($mode !== "none" and $mode !== "rts/cts" and $mode !== "xon/xoff") { trigger_error("Invalid flow control mode specified", E_USER_ERROR); return false; } if ($this->_os === "linux") $ret = $this->_exec("stty -F " . $this->_device . " " . $linuxModes[$mode], $out); else $ret = $this->_exec("mode " . $this->_windevice . " " . $windowsModes[$mode], $out); if ($ret === 0) return true; else { trigger_error("Unable to set flow control : " . $out[1], E_USER_ERROR); return false; } } /** * Sets a setserial parameter (cf man setserial) * NO MORE USEFUL ! * -> No longer supported * -> Only use it if you need it * * @param string $param parameter name * @param string $arg parameter value * @return bool */ function setSetserialFlag ($param, $arg = "") { if (!$this->_ckOpened()) return false; $return = exec ("setserial " . $this->_device . " " . $param . " " . $arg . " 2>&1"); if ($return{0} === "I") { trigger_error("setserial: Invalid flag", E_USER_WARNING); return false; } elseif ($return{0} === "/") { trigger_error("setserial: Error with device file", E_USER_WARNING); return false; } else { return true; } } // // CONFIGURE SECTION -- {STOP} // // // I/O SECTION -- {START} // /** * Sends a string to the device * * @param string $str string to be sent to the device * @param float $waitForReply time to wait for the reply (in seconds) */ function sendMessage ($str, $waitForReply = 0.1) { $this->_buffer .= $str; if ($this->autoflush === true) $this->flush(); usleep((int) ($waitForReply * 1000000)); } /** * Reads the port until no new datas are availible, then return the content. * * @pararm int $count number of characters to be read (will stop before * if less characters are in the buffer) * @return string */ function readPort ($count = 0) { if ($this->_dState !== SERIAL_DEVICE_OPENED) { trigger_error("Device must be opened to read it", E_USER_WARNING); return false; } if ($this->_os === "linux") { $content = ""; $i = 0; if ($count !== 0) { do { if ($i > $count) $content .= fread($this->_dHandle, ($count - $i)); else $content .= fread($this->_dHandle, 128); } while (($i += 128) === strlen($content)); } else { do { $content .= fread($this->_dHandle, 128); } while (($i += 128) === strlen($content)); } return $content; } elseif ($this->_os === "windows") { /* Do nohting : not implented yet */ } trigger_error("Reading serial port is not implemented for Windows", E_USER_WARNING); return false; } /** * Flushes the output buffer * * @return bool */ function flush () { if (!$this->_ckOpened()) return false; if (fwrite($this->_dHandle, $this->_buffer) !== false) { $this->_buffer = ""; return true; } else { $this->_buffer = ""; trigger_error("Error while sending message", E_USER_WARNING); return false; } } // // I/O SECTION -- {STOP} // // // INTERNAL TOOLKIT -- {START} // function _ckOpened() { if ($this->_dState !== SERIAL_DEVICE_OPENED) { trigger_error("Device must be opened", E_USER_WARNING); return false; } return true; } function _ckClosed() { if ($this->_dState !== SERIAL_DEVICE_CLOSED) { trigger_error("Device must be closed", E_USER_WARNING); return false; } return true; } function _exec($cmd, &$out = null) { $desc = array( 1 => array("pipe", "w"), 2 => array("pipe", "w") ); $proc = proc_open($cmd, $desc, $pipes); $ret = stream_get_contents($pipes[1]); $err = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); $retVal = proc_close($proc); if (func_num_args() == 2) $out = array($ret, $err); return $retVal; } // // INTERNAL TOOLKIT -- {STOP} // } ?>
  5. Hi All, I'm not 100% sure if this is the place to be posting for help with this. I have managed to get some source code for a SMS PHP page. However I am having some problems getting it to work, mainly because I'm not 1005 sure how to configure it, and if I need to make any toher changes to the code in order to incorporate my SMS gateway. The error message I am getting is: "SMS Sending Failed Message:Network error unable to send the message", this mesage is however coded into the code. Below is the code of the 4 different pages: HTML Page where message is created <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title>SMS Sending Service</title> <style type="text/css"> body { font-family:Verdana,Arial,sans-serif; font-size:100%; } td { vertical-align:top; } input[type=submit] { padding:5px 10px; } </style> <script type="text/javascript" src="send.js"></script> </head> <body> <h1>SMS Sending Service</h1> <form action="send.php" method="post"> <table border="0" cellpadding="5" style="background:#F7F7F7;border:1px solid #CCC;border-radius:5px;-moz-border-radius:5px;"> <tr> <td><label for="method">Tipo di SMS:</label></td> <td> <select name="method" id="method"> <option value="classic">Classic</option> <option value="report">Classic con notifica</option> <option value="basic">Basic</option> </select> </td> </tr> <tr> <td><label for="recipients">Your Valentine's Number: </label></td> <td> <span id="recipients"> <div><input type="text" name="recipients[]" value="27" /></div> </span> <a href="javascript:;" onclick="addRecipient();"><small>Add Another Valentine</small></a> </td> </tr> <tr> <td><label for="text">Message: </label></td> <td><textarea name="text" id="text" cols="30" rows="10"></textarea></td> </tr> <tr> <td></td> <td> <small> Characters Remaining: <span id="leftChars" style="color:#F00;">0</span> / <b id="messageMaxLength">765</b> (<span id="numberOfSMS" style="color:#39b54a;">1</span>) </small> </td> </tr> <tr> <td><label for="sender_number">Sender's Number: </label></td> <td><input type="text" name="sender_number" id="sender_number" /> <small>Eg 27741123456</small></td> </tr> <tr> <td><label for="sender_string">Alphanumeric Sender: </label></td> <td><input type="text" name="sender_string" id="sender_string" maxlength="11" /> <small>Max 11 Characters</small></td> </tr> <tr> <td><label for="charset">Charset</label></td> <td> <select name="charset" id="charset"> <option value="ISO-8859-1">ISO-8859-1</option> <option value="UTF-8">UTF-8</option> </select> </td> </tr> <tr> <td colspan="2" align="right"> <input type="submit" value="Send Message" name="submit" /> </td> </tr> </table> </form> </body> </html> PHP Send page <?php // IMPORTANT: // ENTER YOUR CREDENTIALS HERE VM ini_set('soap.wsdl_cache_enabled',0); ini_set('soap.wsdl_cache_ttl',0); define('VM_WSDL', 'https://myhostserver/WebsiteData/WebsiteDataEndpoint?wsdl'); define('VM_USERNAME','MyGateWayUsername'); define('VM_PASSWORD','MyGateWayPassword'); require('validate.php'); // Collect post data from form $method = $_POST['method']; $recipients = $_POST['recipients']; $text = $_POST['text']; $sender_number = $_POST['sender_number']; $sender_string = $_POST['sender_string']; $charset = $_POST['charset']; $result = VMGatewaySendSMS(VM_USERNAME, VM_PASSWORD, $recipients, $text, $method, $sender_number, $sender_string, $charset); if($result['status']=='success') { echo '<b style="color:#8dc63f;">SMS Sent Successfully</b><br/>'; echo '<b>SMS rimanenti:</b>'.$result['remaining_sms']; } if($result['status']=='failed') { echo '<b style="color:#ed1c24;">SMS Sending Failed</b><br/>'; if(isset($result['code'])) { echo '<b>Codice:</b>'.$result['code'].'<br/>'; } echo '<b>Message:</b>'.urldecode($result['message']); } ?> Send.js file var SMS_CLASSIC_MAX_LENGTH = 765, SMS_BASIC_MAX_LENGTH = 1404, CURRENT_SMS_LENGTH = 765; var translations = Array(); translations['ErrorTextMoreThan']='Attenzione! Il testo non puo\' essere piu\' lungo di '; translations['ErrorChars']=' caratteri!\n'; function addRecipient() { var newRecipient = document.createElement('div'); newRecipient.innerHTML = '<input type="text" name="recipients[]" value="27" /> <a href="javascript:;" onclick="removeRecipient(this.parentNode);"><small>Remove</small></a>'; document.getElementById("recipients").appendChild(newRecipient); } function removeRecipient(obj) { document.getElementById("recipients").removeChild(obj); } window.onload = function() { var msgMaxLen = document.getElementById("messageMaxLength"); document.getElementById("method").onchange = function(){ switch(this.value) { case "classic": case "report": msgMaxLen.innerHTML = SMS_CLASSIC_MAX_LENGTH; CURRENT_SMS_LENGTH = SMS_CLASSIC_MAX_LENGTH; charLeft(); break; case "basic": msgMaxLen.innerHTML = SMS_BASIC_MAX_LENGTH; CURRENT_SMS_LENGTH = SMS_BASIC_MAX_LENGTH; charLeft(); break; } }; document.getElementById("text").onkeyup = function(){ charLeft(); }; }; function charLeft(){ var max = CURRENT_SMS_LENGTH; var smsText = document.getElementById("text").value; var doubleChars = 0; if(smsText==="") { var length = 0; } else { var length = getRealLengthFor(smsText,false); doubleChars = getRealLengthFor(smsText,true); } if (length > max){ document.getElementById("text").value = smsText.substring(0, max-doubleChars); alert(translations['ErrorTextMoreThan'] + max + translations['ErrorChars']); } var leftChars = length; if (leftChars < 0){ leftChars = 0; } document.getElementById("leftChars").innerHTML = leftChars; var numberOfSMS = document.getElementById("numberOfSMS"); var actualNumberOfSMS = 0; switch(max) { case SMS_CLASSIC_MAX_LENGTH: if(length<=160) { numberOfSMS.innerHTML = '1'; } if(length>160) { actualNumberOfSMS = Math.floor((length-1) / 153) + 1; numberOfSMS.innerHTML = actualNumberOfSMS; } break; case SMS_BASIC_MAX_LENGTH: numberOfSMS.innerHTML = getNumberOfSegmentForBasic(smsText.length, smsText); break; } } //from JAVA: //var SPECIAL_CHARS = Array('[', '\\', ']', '^', '{', '|', '}', '~', '¬', 8364); var SPECIAL_CHARS = Array("\x5B", "\x5C", "\x5D", "\x5E", "\x7B", "\x7C", "\x7D", "\x7E", 8364, 49792, 14844588); var CHAR_TO_CUT_BASIC = Array(' ', '.', ',', '?', '!'); // Fa il check se una variabile e' null o vuota function isEmpty( inputStr ) { if ( null == inputStr || "" == inputStr ) { return true; } return false; } // Aggiungo un metodo alla classe string // toCharArray esistente in java String.prototype.toCharArray = function() { var charArr=new Array(); for(var i=0;i<this.length;i++) charArr[i]=this.charAt(i); return charArr; }; // isIntInTheArray // Cerca nell'array chars se e' presente il carattere c // Parametri: // char c, char[] chars function isIntInTheArray(c, chars) { for(var i=0;i<chars.length;i++) { if(chars[i] == c || chars[i] == c.charCodeAt(0)) return true; } return false; } // getRealLengthFor // Parametri: // String s // Return int function getRealLengthFor(s,getDoubleChars) { if (isEmpty(s)) return 0; var chars = s.toCharArray(); var numberOfSpecialChars = 0; for (var k=0; k<chars.length; k++) { if (isIntInTheArray(chars[k], SPECIAL_CHARS)) { numberOfSpecialChars++; } } if(getDoubleChars === true) return numberOfSpecialChars; return s.length + numberOfSpecialChars; } // Conteggio SMS Basic - Mirko Mariani // Traduzione dall'algoritmo JAVA // Return Int // Parametri: // Integer len, String s function getNumberOfSegmentForBasic(len, s) { if (len <= 160) return 1; var leftStringToSplit = s; var segmentNumber = 0, cycle = 0, segmentLength = 0; var c = 'c'; var charForLeftString = null; while (!isEmpty(leftStringToSplit)) { var indexOfEndSegment = -1; var numberOfSpecialChars = 0; if ( cycle == 0 ) { segmentLength = 156; } else { segmentLength = 156; } // Check if we reached the last segment if ( getRealLengthFor( leftStringToSplit , false) > segmentLength ) { charForLeftString = leftStringToSplit.toCharArray(); for ( var k = 0; k < charForLeftString.length; k++ ) { if ( isIntInTheArray( charForLeftString[k], SPECIAL_CHARS ) ) { numberOfSpecialChars++; } } indexOfEndSegment = segmentLength - numberOfSpecialChars; // go to the point where cut the text var charChecked = 0; var charForCuttingFound = false; // search till the 15 char back while ( charChecked < 15 && !charForCuttingFound ) { c = leftStringToSplit.charAt( indexOfEndSegment - charChecked ); if ( isIntInTheArray( c, CHAR_TO_CUT_BASIC ) ) { segmentNumber++; charForCuttingFound = true; } else { charChecked++; } } // if no char has been found the string will be cut at the end of the segment length -> put the charChecked to 0 to // use the substring method below to determine the left string still to split if (!charForCuttingFound ) { segmentNumber++; charChecked = 0; } // change the left string still to split leftStringToSplit = leftStringToSplit.substring( indexOfEndSegment - charChecked, leftStringToSplit.length ); } else { // reset to end the cycle leftStringToSplit = ""; segmentNumber++; } cycle++; } return segmentNumber; } Validate.php <?php define("NET_ERROR", "Network+error+unable+to+send+the+message"); define("SENDER_ERROR", "You+can+specify+just+one+type+of+sender%2C+numeric+or+alphanumberic"); function do_post_request($url, $data, $optional_headers = null){ if(!function_exists('curl_init')) { $params = array( 'http' => array( 'method' => 'POST', 'content' => $data ) ); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { return 'status=failed&message='.NET_ERROR; } $response = @stream_get_contents($fp); if ($response === false) { return 'status=failed&message='.NET_ERROR; } return $response; } else { $ch = curl_init(); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_TIMEOUT,60); curl_setopt($ch,CURLOPT_USERAGENT,'Generic Client'); curl_setopt($ch,CURLOPT_POSTFIELDS,$data); curl_setopt($ch,CURLOPT_URL,$url); if ($optional_headers !== null) { curl_setopt($ch,CURLOPT_HTTPHEADER,$optional_headers); } $response = curl_exec($ch); curl_close($ch); if(!$response){ return 'status=failed&message='.NET_ERROR; } return $response; } } function VMGatewaySendSMS($username,$password,$recipients,$text,$sms_type='basic',$sender_number='',$sender_string='',$charset='',$optional_headers=null) { $url = 'https://Myhostserver/WebsiteData/WebsiteDataEndpoint?wsdl'; switch($sms_type) { case 'classic': $method='send_sms_classic'; break; case 'report': $method='send_sms_classic_report'; break; case 'basic': default: $method='send_sms_basic'; } $parameters = 'method=' .urlencode($method).'&' .'username=' .urlencode($username).'&' .'password=' .urlencode($password).'&' .'text=' .urlencode($text).'&' .'recipients[]='.implode('&recipients[]=',$recipients) ; if($sender_number != '' && $sender_string != '') { parse_str('status=failed&message='.SENDER_ERROR,$result); return $result; } $parameters .= $sender_number != '' ? '&sender_number='.urlencode($sender_number) : ''; $parameters .= $sender_string != '' ? '&sender_string='.urlencode($sender_string) : ''; switch($charset) { case 'UTF-8': $parameters .= '&charset='.urlencode('UTF-8'); break; case '': case 'ISO-8859-1': default: } parse_str(do_post_request($url,$parameters,$optional_headers),$result); return $result; } ?>
  6. Hi! I want to create a PHP site with added SMS functionality (dating services site). I was suggested a gateway to use as the engine (google: ozekisms.com/index.php?owpn=422). I will use Mysql database to puit the records in it. As the documentation mentions PHP website can send SMS messages by simply placing records into a mysql database table called ozekimessageout. So I can create HTML form, that the visitors of the website will fill in. When the form is submitted I am able to create record in the ozekimessagout database table using an SQL INSERT statement. See example: <HTML> <BODY> <H1> Send an SMS </H1> <?php $phonenum = $_GET['phonenum']; $messagetext = $_GET['messagetext']; if ($phonenum<>'') { $conn = mysql_connect("localhost", 'ozeki', 'abc123'); if (!$conn) { die('Could not connect to database ' . mysql_error()); } mysql_select_db('ozekisms'); $sql = "INSERT INTO ozekimessageout (receiver,msg,status) ". "VALUES ('$phonenum','$messagetext','send')"; mysql_query($sql); mysql_close($conn); echo "The message has been submitted for sending <br><br>"; } ?> <FORM action=send.php METHOD=GET> Mobil phone number: <INPUT TYPE="TEXT" SIZE="16" NAME="phonenum" VALUE="+44777888999"> <br> <TEXTAREA NAME="messagetext" ROWS=5 COLS=40>Hello world</TEXTAREA> <br> <INPUT TYPE=SUBMIT VALUE=SEND> </FORM> </BODY> </HTML> To receive SMS messages all Ihave to do is select the records from the ozekimessagin database table. This can be done by issuing a simple SQL SELECT statement. <HTML> <BODY> <H1>List incoming messages</H1> <?php $conn = mysql_connect("localhost", 'ozeki', 'abc123'); mysql_select_db('ozekisms'); $sql = "SELECT sender,senttime,msg FROM ozekimessagein ORDER BY senttime desc"; $res = mysql_query($sql); $cn = mysql_num_rows($res); for ($x=0;$x<$cn;$x++) { list ($sender,$senttime,$msg) = mysql_fetch_row($res); echo "<li>$senttime, <b>$sender</b>, $msg"; } mysql_close($conn); ?> </BODY> </HTML> Maybe you can get some useful idea from this description and if you have better solutions to insert or select records into Mysql database, please share with me. TX, Boris
×
×
  • Create New...

Important Information

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.