i have awebsite with php i would like to send SMS to clients.How i do it?
what are the requirements for that?thankz in advance
sending SMS
I have written an entire web application around sending pager and "SMS" messages.
Basically, it boils down to sending either an email message to the phone or pager or connecting to an SNPP server to have the message transmitted to a pager or phone.
It seams as though more pager and phone companies are moving away from SNPP and towards email and strict SMS.
SMS strictly speaking usually requires paying a fee to connect a SMS server to transmit your message. Not something I am interested in doing.
I am glad to share my code with you if you want. Go to MyPageAll.com for more info and let me know if you want examples of connecting to a SNPP server and such.
You might do a few Google / Wikipedia searches on these terms to get a feel for what you really want to do:
SMS (Short Message Service)
SNPP (Siimple Network Paging Protocol)
TAP (Telocator Alphanumeric Protocol)
SMTP (Simple Mail Tranport Protocol)
My system is used by a fire department for emergency notifications as well as other general use and it sends messages very quickly to several different pager and cell phone company devices using both SMTP and SNPP.
firemankurt, plz give some sample code for that
I an rewriting code today and will try post it later.
Here it is... Have not tested it since rewrite yet.
<?php
/* Constants */
define("ConnRetries",3); // How many times should I try connect to the SNPP Server
define("PageRetries",3); // How many times should I try send pager PIN to the SNPP Server
define("MessRetries",3); // How many times should I try send Message to the SNPP Server
define("SendRetries",3); // How many times should I try send SEND command to the SNPP Server
define("QuitRetries",3); // How many times should I try send QUIT comand to the SNPP Server
define("ConnSuccess","220"); // a portion of the return line to evaluate for success such as a numbered response
define("PageSuccess","250"); // a portion of the return line to evaluate for success such as a numbered response
define("MessSuccess","250"); // a portion of the return line to evaluate for success such as a numbered response
define("SendSuccess","250"); // a portion of the return line to evaluate for success such as a numbered response
define("QuitSuccess","221"); // a portion of the return line to evaluate for success such as a numbered response
/*
2xx - Successful, continue
3xx - Begin DATA input (see "DATA" command)
4xx - Failed with connection terminated
5xx - Failed, but continue session
SNPP version 3 (two-way) adds the following categories:
7xx - UNsuccessful two-way specific transaction, but continue session
8xx - Successful two-way specific transaction, continue
9xx - Successful QUEUED two-way transaction, continue
*/
/*
###############################################################
# ProcessSNPPConnection(
# $ProviderName - is the Name of the provider currently being processed
# $PagerArray - is the PIN values currently being processed
# $MemArray - is the Member numbers for PINs currently being processed
###############################################################
*/
function ProcessSNPPConnection($Provider,$PagerArray,$MemArray){
global $Message,$telnetPointer;
// initialize array for log query
$PageLogEntQry = array();
//===================== $Provider Keys: =====================================================
//Indicator Description Method NumOnly Server Port EndLine Note
//===========================================================================================
// ############################## try connect #######################################
list($Success,$LogArray[],$Fails) = SNPPconnect($Provider['Server'],$Provider['Port']);
$Failures += $Fails;//add any fails to transaction total Failures
if ($Success !== false)// if connection was successful then continue
{ // SNPP connect
// process each pager number in the PagerArray
foreach ($PagerArray as $Key =>$pagernumber)
{// each pagernumber
// ############################## CreatePIN ##########################################
list($Success,$LogString[],$Fails,$PagerPin) = CreatePIN($pagernumber);
$Failures += $Fails;//add any fails to transaction total Failures
if ($Success)// if CreatePIN was successful then continue
{// CreatePIN
// ############################## Send PIN ##########################################
list($Success,$LogString[],$Fails) = SendPageComm($Pager);
$Failures += $Fails;//add any fails to transaction total Failures
if ($Success)// if SendPIN was successful then continue
{// Send PIN
// ############################## Send Message #######################################
list($Success,$LogString[],$Fails) = SendMessComm($Message);
$Failures += $Fails;//add any fails to transaction total Failures
if ($Success)// if Send Message was successful then continue
{ //Send Message
// ############################## Send SEND ##########################################
list($Success,$LogString[],$Fails) = SendSend();
$Failures += $Fails;//add any fails to transaction total Failures
} //Send Message
}// Send PIN
}// CreatePIN
$PINLog = implode("",$LogString);
unset($LogString);
$LogArray[] = $PINLog;
// Make SQL Log Entry
$PageLogEntQry[] = array($MemArray[$Key], $Value, $Fails,$PINLog); // `MEMNUM`,`PIN`,`PINSTAT`
} // each pagernumber
// ############################## try disconnect #######################################
// Paging is done so send Quit command to try end nicely
list($Success,$LogString[],$Fails) = SendQuit();// ($Success,$DetResponse,$GenResponse)
$Failures += $Fails;//add any fails to transaction total Failures`
// close connection to free resource
fclose($telnetPointer);
}// SNPP connect
return array($LogString,$Failures,$PageLogEntQry);
}
/* Open Connection to SNPP server
return true if successful*/
function SNPPconnect($Address,$Port){
global $telnetPointer;
$Tries = 0; // Set number of tries to 1 to begin
while (++$Tries <= ConnRetries){ // increment $Tries and then evaluate it
//fsockopen ( string target [, int port [, int &errno [, string &errstr [, float timeout]]]] )
$telnetPointer = fsockopen($Address, $Port, $errno, $errstr, 30);
$response = preg_replace ('/[^0-9,A-Z,a-z,\s]/i',"", fgets($telnetPointer)); // Get Response from server
$Success = strpos($response, ConnSuccess); // evaluate response for success
if ($Success !== false) {break;} //stop trying if successful
}
$Failures = ($Success === false)?1:0;
$Action = "Connect|try=".$Tries."|Open Socket".$Address.":".$Port."|".(trim($response))."\n";
return array($Success,$Action,$Failures); // Return final response
}
/* Strip all characters except
numbers from pager number */
function CreatePIN($pagernumber){
$PagerPIN = preg_replace ('/[^0-9]/i',"", $pagernumber); // strip all but numbers
$Success = (strlen($PagerPIN) == 10)?true:false;// Check for 10 digit phone number
$Failures = ($Success === false)?1:0;
$Action .= "CreatePIN|try=1".$PagerNumber."|".$PagerPIN."\n";
return array($Success,$Action,$Failures,$PagerPIN);
}
/*Send "Who to Page" line to SNPP server
return true if successful*/
function SendPageComm($Pager){
global $telnetPointer; // Get global variables
$Tries = 0; // Set number of tries to 0 to begin
$Pageline = "PAGE ".$Pager."\r\n"; // Compose Page command from components
while ((++$Tries) <= PageRetries){ // increment $Tries and then evaluate it
fwrite($telnetPointer, $Pageline); // Send Page line
$response = preg_replace ('/[^0-9,A-Z,a-z,\s]/i',"", fgets($telnetPointer)); // Get Response from server
$Success = strpos($response, PageSuccess); // evaluate response for success
if ($Success !== false) {break;} //stop trying if successful
}
$Failures = ($Success === false)?1:0;
$Action .= "SEND PIN|try=".$Tries."|".$Pageline."|".(trim($response))."\n";
return array($Success,$Action,$Failures);
}
/* Send Message line to SNPP server
return true if successful*/
function SendMessComm($Message){
global $telnetPointer; // Get global variables
$Tries = 0; // Set number of tries to 0 to begin
$Messline = "MESS ".$Message."\r\n"; // Compose message command from components
while ((++$Tries) <= MessRetries){ // increment $Tries and then evaluate it
fwrite($telnetPointer, $Messline); // Send message line
$response = preg_replace ('/[^0-9,A-Z,a-z,\s]/i',"", fgets($telnetPointer)); // Get Response from server
$Success = strpos($response, MessSuccess); // evaluate response for success
if ($Success !== false) {break;}
}
$Failures = ($Success === false)?1:0;
$Action .= "SEND MESS|try=".$Tries."|".$Messline."|".(trim($response))."\n";
return array($Success,$Action,$Failures);
}
/* Send Send line to SNPP server
return true if successful*/
function SendSend(){
global $telnetPointer; // Get global variables
$Tries = 0; // Set number of tries to 0 to begin
$Sendline = "SEND \r\n"; // Compose Send line from components
while ((++$Tries) <= SendRetries){ // increment $Tries and then evaluate it
fwrite($telnetPointer, $Sendline); // Send SEND line
$response = preg_replace ('/[^0-9,A-Z,a-z,\s]/i',"", fgets($telnetPointer)); // Get Response from server
$Success = strpos($response, SendSuccess); // evaluate response for success
if ($Success !== false) {break;}
}
$Failures = ($Success === false)?1:0;
$Action .= "SEND SEND|try=".$Tries."|".$Sendline."|".(trim($response))."\n";
return array($Success,$Action,$Failures);
}
/* Send Quit line to SNPP server
return true if successful*/
function SendQuit(){
global $telnetPointer; // Get global variables
$Tries = 0; // Set number of tries to 1 to begin
$Quitline = "QUIT \r\n"; // Compose Send line from components
while ((++$Tries) <= QuitRetries){ // increment $Tries and then evaluate it
fwrite($telnetPointer, $Quitline); // Send SEND line
$response = preg_replace ('/[^0-9,A-Z,a-z,\s]/i',"", fgets($telnetPointer)); // Get Response from server
$Success = strpos($response, QuitSuccess); // evaluate response for success
if ($Success !== false) {break;}
}
$Failures = ($Success === false)?1:0;
$Action .= "SEND QUIT|try=".$Tries."|".$Quitline."|".(trim($response))."\n";
return array($Success,$Action,$Failures);
}
?>
Here is how you call it:
<?php
//Sample call to ProcessSNPPConnection function:
// Call ProcessSNPPConnection() in SNPPprocess.php and get return values
list( $LogString, // returned Detail Log of all actions
$Failures, // returned Number of Failures
$PageLogEntQry // returned Array of arrays containing values to enter into the 'pagelogent' table
) =
ProcessSNPPConnection(
$Provider, // array containing all settings for this provider
$PagerArray, // array containing all pager numbers to send to using this provider
$MemArray // array contains all user numbers keyed to match pager number array
);
?>
Here are the values I have in my DB for each provider.
$Provider, // array containing all settings for this provider
provider table: (Only SNPP Method providers can be processed here)
--
-- Table structure for table MPAProvider
CREATE TABLE MPAProvider
(
Indicator
varchar(8) NOT NULL default '',
Description
varchar(35) NOT NULL default '',
Method
varchar(5) NOT NULL default '',
NumOnly
tinyint(1) NOT NULL default '0',
Server
varchar(40) NOT NULL default '',
Port
smallint(5) unsigned NOT NULL default '0',
EndLine
varchar(10) NOT NULL default '',
Note
varchar(255) NOT NULL default '',
PRIMARY KEY (Indicator
)
) TYPE=MyISAM;
--
-- Dumping data for table MPAProvider
INSERT INTO MPAProvider
VALUES
('ATT', 'AT&T using SNPP', 'SNPP', 1, '67.115.154.70', 444, '\r\n', 'AT&T using SNPP'),
('ATT2', 'AT&T cellular using email', 'SMTP', 1, '@mmode.com', 0, '', 'AT&T cellular using email'),
('COB', 'City Of Bellingham email', 'SMTP', 0, '@cob.org', 0, '', 'City Of Bellingham email'),
('CING', 'Cingular Pager (Not Cell) SNPP', 'SNPP', 1, 'snpp.cingular.com', 444, '\r\n', 'Cingular Pager (Not Cell) SNPP'),
('CING2', 'Cingular cellular using email', 'SMTP', 1, '@.mycingular.com', 0, '', 'Cingular cellular using email'),
('COOK', 'Cook Paging by SNPP', 'SNPP', 1, '67.115.154.70', 444, '\r\n', 'Cook Paging by SNPP'),
('COOK2', 'Cook Paging by email', 'SMTP', 1, '@cookmail.com', 0, '', 'Cook Paging by email'),
('NEXTEL3', 'NEXTEL cellular using SNPP', 'SNPP', 1, 'snpp.nextel.com', 444, '\r\n', 'NEXTEL cellular using SNPP'),
('NEXTEL2', 'NEXTEL cellular using email', 'SMTP', 1, '@messaging.nextel.com', 0, '', 'NEXTEL cellular using email'),
('SKY', 'Skytel messaging using SNPP', 'SNPP', 1, 'snpp.skytel.com', 444, '\r\n', 'Skytel messaging using SNPP'),
('SKY2', 'Skytel messaging using email', 'SMTP', 1, '@skytel.com', 0, '', 'Skytel messaging using email'),
('SPRINT2', 'Sprint PCS cellular using email', 'SMTP', 1, '@messaging.sprintpcs.com', 0, '', 'Sprint PCS cellular using email'),
('TMOBIL', 'T-Mobile cellular using email', 'SMTP', 1, '@tmomail.net', 0, '', 'T-Mobile cellular using email'),
('VTEXT', 'Verizon Cellular using email', 'SMTP', 1, '@vtext.com', 0, '', 'Verizon Cellular using email'),
('OTHER', 'Other email', 'SMTP', 0, '@', 0, '', 'Other email'),
('', 'NONE', '', 0, '', 0, '', 'NONE'),
('BOOST', 'Boost Mobile using email', 'SMTP', 1, '@myboostmobile.com', 0, '', 'Boost Mobile using email'),
('METRO', 'Metrocall using SNPP', 'SNPP', 1, 'snpp.metrocall.com', 444, '\r\n', 'Metrocall using SNPP'),
('METRO2', 'Metrocall using email', 'SMTP', 1, '@.metrocall.com', 0, '', 'Metrocall using email'),
('NEXTEL', 'NEXTEL paging using email', 'SMTP', 1, '@.nextel.com', 0, '', 'NEXTEL paging using email');