Page 1 of 5 123 ... LastLast
Results 1 to 15 of 64

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:
    <form id="sms" name="sms" method="post" action="scripts/send_sms.php">
    <table width="400">
        <td align="right" valign="top">From:</td>
        <td align="left"><input name="from" type="text" id="from" size="30" /></td>
        <td align="right" valign="top">To:</td>
        <td align="left"><input name="to" type="text" id="to" size="30" /></td>
        <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>
        <td align="right" valign="top">Message:</td>
        <td align="left"><textarea name="message" cols="40" rows="5" id="message"></textarea></td>
        <td colspan="2" align="right"><input type="submit" name="Submit" value="Submit" /></td>
    The handler:
    $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
    Camposol, Mazarron. Spain
    what countries will this work with? etc...

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

  4. #4
    Join Date
    Jun 2003
    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
    Cleveland, OH
    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
    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
    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
    The Garden State
    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
    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>
    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 03:20 PM.
    We do precision guesswork

  11. #11
    Join Date
    Mar 2008
    Sri Lanka

    it's working in Sri Lanka mobitel network

  12. #12
    Join Date
    Nov 2008

    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
    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.


    Who is paying for the texts? Are you charged to receive them? This says it's free

    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)


    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?
    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 04: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
    Leeds, Yorkshire, England
    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
    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 1 users browsing this thread. (0 members and 1 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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.16474 seconds
  • Memory Usage 3,031KB
  • Queries Executed 15 (?)
More Information
Template Usage (38):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)bbcode_html
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (15)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (15)postbit
  • (15)postbit_onlinestatus
  • (15)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (74):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates