www.webdeveloper.com
Page 1 of 5 123 ... LastLast
Results 1 to 15 of 62

Thread: Send SMS (text messages) via PHP

  1. #1

    Send SMS (text messages) via PHP

    I figured this out the other day and thought it would be a good idea to pass on. SMS messages are just sent to special email addresses, so they can be sent from server to phone with minimal effort. Here is the form and handler, feel free to copy or modify it in any way you see fit:

    The form:
    Code:
    <form id="sms" name="sms" method="post" action="scripts/send_sms.php">
    <table width="400">
      <tr>
        <td align="right" valign="top">From:</td>
        <td align="left"><input name="from" type="text" id="from" size="30" /></td>
      </tr>
      <tr>
        <td align="right" valign="top">To:</td>
        <td align="left"><input name="to" type="text" id="to" size="30" /></td>
      </tr>
      <tr>
        <td align="right" valign="top">Carrier:</td>
        <td align="left"><select name="carrier" id="carrier">
          <option value="verizon">Verizon</option>
          <option value="tmobile">T-Mobile</option>
    	  <option value="sprint">Sprint</option>
    	  <option value="att">AT&amp;T</option>
    	  <option value="virgin">Virgin Mobile</option>
        </select></td>
      </tr>
      <tr>
        <td align="right" valign="top">Message:</td>
        <td align="left"><textarea name="message" cols="40" rows="5" id="message"></textarea></td>
      </tr>
      <tr>
        <td colspan="2" align="right"><input type="submit" name="Submit" value="Submit" /></td>
        </tr>
    </table>
    </form>
    The handler:
    Code:
    <?php
    $from = $_POST['from'];
    $to = $_POST['to'];
    $carrier = $_POST['carrier'];
    $message = stripslashes($_POST['message']);
    
    if ((empty($from)) || (empty($to)) || (empty($message))) {
    header ("Location: sms_error.php");
    }
    
    else if ($carrier == "verizon") {
    $formatted_number = $to."@vtext.com";
    mail("$formatted_number", "SMS", "$message"); 
    // Currently, the subject is set to "SMS". Feel free to change this.
    
    header ("Location: sms_success.php");
    }
    
    else if ($carrier == "tmobile") {
    $formatted_number = $to."@tomomail.net";
    mail("$formatted_number", "SMS", "$message");
    
    header ("Location: sms_success.php");
    }
    
    else if ($carrier == "sprint") {
    $formatted_number = $to."@messaging.sprintpcs.com";
    mail("$formatted_number", "SMS", "$message");
    
    header ("Location: sms_success.php");
    }
    
    else if ($carrier == "att") {
    $formatted_number = $to."@txt.att.net";
    mail("$formatted_number", "SMS", "$message");
    header ("Location: sms_success.php");
    }
    
    else if ($carrier == "virgin") {
    $formatted_number = $to."@vmobl.com";
    mail("$formatted_number", "SMS", "$message");
    
    header ("Location: sms_success.php");
    }
    ?>
    Sending a text message to a cell phone through PHP is just a matter of appending the correct suffix to the number and using the mail() function. If you want to add more carriers, go here and find the carrier you are looking for. If you do not know the carrier (ie. if you want to add a "not sure" option to the pulldown menu), add @teleflip.com as the suffix. The phone numbers must be 10 digits long (XXX-XXX-XXXX).

    Feel free to contact me if you are having any trouble,
    The Yembo Project

  2. #2
    Join Date
    Jan 2008
    Location
    Camposol, Mazarron. Spain
    Posts
    3
    what countries will this work with? etc...

  3. #3
    Join Date
    May 2004
    Posts
    288
    dont think this would work in the uk

  4. #4
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    I tried the email deal, first email got no response or text, second got bounced back with the message: "this does not appear to be a valid north american phone number", so I'm guessing only U.S. no.s right?
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  5. #5
    Join Date
    May 2007
    Location
    Cleveland, OH
    Posts
    1,403
    I don't have time to try this now, but if this works for someone let me know. If it works I might write a little Adobe Air app when I get time to text message people from my computer at work (without an IM client).

  6. #6
    I'm in the US. Theoretically, it should work outside of the US if you use the right gateway, but I can't try it since I can't leave the US.

  7. #7
    Join Date
    Jan 2008
    Posts
    17
    Sir, how about the opposite way. From cell to website. e.g. if the user send message, then in the website, there is a part where all the messages can be view. Any idea how to do this?

  8. #8
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    look on the wikipedia page he provided, there are 2 sites listed that do sms to email
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  9. #9
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    unfortunately, this solution makes a lot of assumptions (each phone number can be reached at an email address, service providers allow for bulk emails in this fashion, etc) that just aren't true everywhere, even inside the US.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  10. #10
    Join Date
    May 2003
    Posts
    598
    I have had an sms form on my site for a while. The problem I run into is that many sms relays only support limited header info, which means that creating a message that can be "Replied To:" reliably when it was created from a web form is sketchy...but sending the message has worked well.

    You can scale back on the coding by concatenating the number to the carrier from the web form, then the php script just ties the two together:
    HTML Code:
        <p style="text-align:left">Recipient's 10 digit #:<br>
         <input name=number type=text id=number size=12 maxlength=14> @ 
          <select name=carrier id=carrier>
    	<option>-=Select A Carrier=-</option>
            <option value=@message.alltel.com>Alltel</option>
            <option value=@myboostmobile.com>Boost</option>
            <option value=@mobile.mycingular.com>Cingular</option>
            <option value=@messaging.nextel.com>Nextel</option>
            <option value=@tmomail.net>T-Mobile USA</option>
            <option value=@vtext.com>Verizon Wireless</option>
            <option value=@vmobl.com>Virgin Mobile USA</option>
          </select>
        </p>
    PHP Code:
    ...
    ....

    $number trim($_POST['number']);
    $carrier $_POST['carrier'];
    $to $number.$carrier;

    ..
    ...
    ....
    $success mail($to$subject$Body$headers); 
    Last edited by hastx; 01-09-2008 at 02:20 PM.
    We do precision guesswork

  11. #11
    Join Date
    Mar 2008
    Location
    Sri Lanka
    Posts
    43
    http://mayuonline.com/eblog/send-fre...mobitel-lanka/

    it's working in Sri Lanka mobitel network

  12. #12
    Join Date
    Nov 2008
    Posts
    1

    what if you dont know the carrier you're sending to?

    What if i want to have the script send to each of the possible carriers in my country, and get the right one by trial and error?

  13. #13
    Join Date
    Apr 2007
    Posts
    1,664
    Works for me, nice find. Here's a couple of pages that list the emails. My at&t phone is still using the cingular domain. Sent from my gmail account to my phone. Very cool.

    http://www.overseer-network-monitor....Email-List.asp
    http://www.notepage.net/smtp.htm

    Who is paying for the texts? Are you charged to receive them? This says it's free
    http://www.attusers.com/sms/

    A few years ago I worked with for a company that developed a service with Vodafone in the UK on a reverse billing text chat service that made the company (and Vodafone) a small fortune. We paid about 4p a text and charged a lot more depending gong the service.

    If you're interested in using SMS reliably you need a contract and a gateway,. For us back then it worked like this (in the UK). We advertised a short code like 8008 and a key word like 'chat' so the ad would run saying text 'chat' to 8008. The text went to Vodafone and they http posted it to us via their gateway. We stored the number in our database and used either a human operator or robot to reply (again depending on the service) using http to send to the gateway. The user would reply to the text directly and the gateway would again send through to us with their message. We wrote an interface that organized the messages for reply. It was quite a laugh as no-one had a service like that back then (around 2000) but when they also wanted an adult service the message logs became very very scary. I thought I could sue for emotional damage after a few of them.

    They charged about one pound fifty a text and here's how 90&#37; of adult the conversations went.

    Welcome, send you message to start chatting.
    Hi whats your name?
    Sally how are things with you?(1.50)
    Not bad, are you feeling horny?
    you bet, how about you?(1.50)
    Great, what do you look like?
    Blond, Petite, big boobs (1.50)
    Do you take it up the arse?
    You're a bit forward aren't you, is that what you like?(1.50)

    nothing

    That's why we wrote the robot. almost every one did the same thing and asked that same question so we though why pay a team of people when we can bot it. It didn't affect the monthly revenue at all.

    We had one woman call in irate that we had show up on her bill. My boss was a very cool guy and tried to clam her down while we looked into the message logs. The call went like this

    Rant... tirade.. how dare you...refund ....lawsuit etc
    We don't know how it could happen it's a subscription service.
    rant ... fume...
    Does anyone have access you your phone
    no, husband has his own ... seethe .... scream
    (we check logs)
    (He puts her on speaker for the whole office.)
    Is your husbands name David?
    .....silence.....
    Hello?
    ...yes....
    Because we have these messages ('my name Davids... messages descend into filth)
    ....silence.....OK thank you, goodbye.

    Dam if that wasn't the funniest day in a very fun place to work!
    Last edited by SyCo; 11-07-2008 at 03:27 PM.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

  14. #14
    Join Date
    Aug 2007
    Location
    Leeds, Yorkshire, England
    Posts
    387
    Take a look at bulksms.

    You can incorporate into php scripts to send SMS and also receive replies back to an e-mail address.

  15. #15
    Join Date
    Jan 2009
    Posts
    1
    Sir, how about the opposite way. From cell to website. e.g. if the user send message, then in the website, there is a part where all the messages can be view. Any idea how to do this? i am also in search of same code can u pls tell me that it possible if yes the pls provide guid line for it .Is there any requirement of hardware or have to purchase any packages

Thread Information

Users Browsing this Thread

There are currently 5 users browsing this thread. (0 members and 5 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles