NEED help : SMS Texting script, example inside

Discussion in 'Programming' started by gweb, Jan 7, 2008.

  1. #1
    Hi I need help,

    I had a script but it turns out that it doesn't cut the mustard.. I have found a site that allows texts to UK and USA mobs which is what I need..

    If anyone can tell me whatscript they are using or knows of a similar script, please help!

    Example site

    Thanks, reps waiting for any genuine advice.
     
    gweb, Jan 7, 2008 IP
  2. jwlnewsome

    jwlnewsome Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i use this class in php

    provider = MORETEXT - hxxp://www.moretext.com/


    <?
    //----------------------- Class to send SMS messages from Web -----------------------------//
    // provider URL = MORETEXT - hxxp://www.moretext.com/sendsms.pl
    class SMS{
    // class variables
    var $_curl = "/usr/local/bin/curl";
    var $_url = "";
    var $_user = "";
    var $_pass = "";
    var $_error = "";
    var $_sent = 0;
    var $_remaining = 0;
    var $_charged = 0;
    var $originator = "";
    //-------------------- Constructor function, set up object -------------------------//
    // parameter 1 - the url to curl for send message, defined by provider
    // hxxp://www.moretext.com/sendsms.pl

    // parameter 2 - the username to connect to provider with
    // test: Entamediatest live: entamedia

    // parameter 3 - the password to connect to provider with


    function SMS($url, $user, $pass){
    $this->_url = $url;
    $this->_user = $user;
    $this->_pass = $pass;
    }
    //--------------------- function to send SMS message -------------------------------//
    // parameter 1 - the numbers to send to, this value can be a string or an array
    // - to send to multiple numbers either use an array or send a comma(,)
    // - separated string
    // parameter 2 - the message to send, can not be more than 160 or less than 1 in length
    // parameter 3 - the originator, or from address. Can be left blank to use provider default
    function Send($numbers, $message, $originator = ""){

    if(!eregi("^[[:space:]#-&!()*+,'-£@_=.:^;a-zA-Z0-9]{1,160}$", $message)){// check message is valid format
    $this->_error = "Invalid message format!";// set the error message
    return false;// return false, invalid message
    }

    // create the number parameter to send message to
    $sendTo = "-d Number='";
    if(is_array($numbers)){// check if sending to multiple numbers
    foreach($numbers as $number){// loop through numbers
    $sendTo .= escapeshellarg($number).",";// addd number to parameter
    }
    $sendTo = substr($sendTo, 0, strlen($sendTo)-1);// remove trailing ','
    }else{// not an array of numbers
    $sendTo .= escapeshellarg($numbers);// set the number parameter to send to
    }
    $sendTo .= "'";

    // create the parameters string
    $parameters = "-d User='".$this->_user."'";// add username
    $parameters .= " -d Pass='".$this->_pass."'";// add password
    if(trim($originator) != ""){// check if originator set
    $parameters .= " -d Originator='".$originator."'";// add originator
    }
    $parameters .= " ".$sendTo;// add numbers to send to
    $parameters .= " -d Message='".urlencode($message)."'";// add message to send

    exec($this->_curl." ".$parameters." ".$this->_url, $result);// execute the command to send message

    $status = explode(":", $result[0]);// get the status of the send
    //print_r($result);
    switch(trim(strtolower($status[1]))){// check the staus of the send
    case "sent":// status sent
    $charged = explode(":", $result[2]);// get the number of messages charged
    $sent = explode(":", $result[1]);// get the number of messages sent
    $remaining = explode(":", $result[3]);// get the credit remaining
    $this->_charged = trim($charged[1]);// set the number of charged messages
    $this->_sent = trim($sent[1]);// set the number of sent messages
    $this->_remaining = trim($remaining[1]);// set the remaining credit
    $this->originator = $originator;//set the originator
    return true;// return true, message sent
    break;
    case "invalid origination address":// error status
    $this->_error = "Invalid originator value!";// set the error message
    return false;// return false, invalid originator value
    break;
    case "insufficient credits":// error status
    $this->_error = "Insufficient credit to send messages";// set the error message
    return false;// return false, not enough credit
    break;
    case "invalid login":// error status
    $this->_error = "Invalid username or password!";// set the error message
    return false;// return false, invalid login details
    break;
    default:// status string not matched
    $this->_error = "Unknown response from provider!";// set the error message
    return false;// return false, unknown response
    break;
    }
    }
    }
    ?>
     
    jwlnewsome, Jan 8, 2008 IP
  3. chrissyj

    chrissyj Peon

    Messages:
    56
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey there! Most cell phones allow you to test vi EMAIL these days, at least in the US. No special code needed - just send an e-mail.....
     
    chrissyj, Jan 8, 2008 IP
  4. gweb

    gweb Well-Known Member

    Messages:
    1,167
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    130
    #4
    Yes but I wanted to be able to do other countries as well as USA - thanks for input though, the U.S system is good.. other countries are harder to do.
     
    gweb, Jan 8, 2008 IP
  5. chrissyj

    chrissyj Peon

    Messages:
    56
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    To do SMS to other countries you need to use one of the SMS services. They are fairly expensive ($450/mo + $0.10/msg), but they do all the work for you - they figure out the carrier, then they forward your msg to that carrier for the destination phone.

    PM me if you want more info.
     
    chrissyj, Jan 8, 2008 IP
    gweb likes this.
  6. gweb

    gweb Well-Known Member

    Messages:
    1,167
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    130
    #6
    Hey thanks for your help, reps coming your way ;)

    Yes please, I will PM you with my questions.. thanks, I really appreciate that.. :)
     
    gweb, Jan 8, 2008 IP
  7. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #7
    There is no "standard" script that you can use as each provider uses their own software and protocol (facebook and myspace are both social networks but have different processes for changing your profile).

    A provider should give you a reasonable example of the script needed to send SMS message via their API.... this is assuming you are using an API/ website solution provider and not trying to spam another SMS website meant only for end users not other sites.

    I thought email-to-X type services had gone out of fashion? Not sure I would want to be paying 10p a message or such for any email that is fained as coming from my account to my email-to system - could get expensive very quickly.
     
    AstarothSolutions, Jan 8, 2008 IP
  8. chrissyj

    chrissyj Peon

    Messages:
    56
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hello, all! I hate to disagree with AstarothSolutions, but there ARE standard scripts out there that will hit every cell phone in a long list of countries. These scripts are provided by 3rd party companies who charge significant fees to provide that kind of "transparent" access. The message is sent to their servers (via their API), and their servers figure out which carrier is providing service and then do whatever conversion is needed to get the message to the phone via that phone's carrier. If that's what you need to do, it's out there.
     
    chrissyj, Jan 9, 2008 IP
  9. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I think you are miss understanding me... yes a single supplier will have a script for their service but you wouldnt be able to use that same script with every supplier because there are many different interfaces to the SMS server apps.
     
    AstarothSolutions, Jan 9, 2008 IP
  10. chrissyj

    chrissyj Peon

    Messages:
    56
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #10
    But, if a service supplier can hit ALL the carriers, why would you NEED any other script?

    THINK about it.....
     
    chrissyj, Jan 10, 2008 IP
  11. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I am not saying you would need any other script.... I am saying you cannot come to a forum and say "I need a script to be able to send an SMS to a mobile phone that will work with any solution provider" as unlike a sendmail type script it is providing an interface to a non-standardised server.

    The OP originally said:

    Hence my comment that you cannot just change the script that you use but need to change the service provider too. Ie if there issue with using script/ Provider A is that they dont give a conformation of delivery then just by changing script but not provider will not help.
     
    AstarothSolutions, Jan 10, 2008 IP
  12. chrissyj

    chrissyj Peon

    Messages:
    56
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Now I see what you are saying Astaroth Solutions - yes, that makes sense.
     
    chrissyj, Jan 14, 2008 IP