TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-15-2010, 03:10 PM   #1 (permalink)
The Wanderer
 
Join Date: Jul 2010
Posts: 17
Thanks: 0
Arictos is on a distinguished road
Default SMS Texting class

Hey there. I haven't found a lot of resources on the web regarding PHP->SMS stuff, most of it is send text to ##########@txt.att.net (or other specified provider), in some cases you can specify a return address, other times it's completely fail and specifies your nameservers instead of a domain, and other random interesting quirks.

So anyway, here is what I ended up putting together.

Things it supports:
  • You only need to specify the 10 digit number, not the carrier
  • Verizon headers to ensure a proper return address
  • Other carriers support the reply "mask" that you can specify rather than an email

Note: I've only tested this on Verizon and AT&T, so if you have another carrier, please test it and let me know if it works the same on there, but I believe it will preform well.

It's really not that great of work, but hopefully it'll save someone the hassle of having to do it again. If you have anything that would improve it, feel free to add on :)
PHP Code:
<?php
        
    
/**
     * Short Message Service (SMS) class
     * 
     * This class is meant to provide communication to a mobile
     * phone, regardless of the carrier provided.
     * 
     * @author        Chase Hutchins    <arictos@gmail.com>
     * @version        0.1
     */
    
class SMS
    
{
        
/**
         * Extensions of all supported carriers
         * 
         * @var        array
         */
        
protected $carriers                = Array(
            
'Airtel (18 circles)'        => 'aircel.co.in',
            
'Airtel (Andhra Pradesh)'    => 'airtelap.com',
            
'Airtel (Karnataka)'        => 'airtelkk.com',
            
'Alaska Communication'        => 'msg.acsalaska.com',
            
'Alltell Wireless'            => 'message.alltel.com',
            
'AQL'                        => 'text.aql.com',
            
// AT&T is used a the "default" recieving party, so we do not need to resend to them
            //'AT&T'                        => 'txt.att.net',
            
'AT&T Godfathered'            => 'mmode.com',
            
'AT&T Paging'                => 'page.att.net',
            
'Bell Mobility'                => 'txt.bell.ca or',
            
'Boost Mobile'                => 'myboostmobile.com',
            
'Bouygues Telecom'            => 'mms.bouyguestelecom.fr',
            
'Loop (BPL Mobile)'            => 'bplmobile.com',
            
'Cellular One'                => 'mobile.celloneusa.com',
            
'Cingular'                    => 'cingular.com',
            
'Centennial Wireless'        => 'cwemail.com',
            
'Cincinnati Bell'            => 'gocbw.com',
            
'Cingular (GoPhone)'        => 'cingulartext.com',
            
'Claro (Brazil)'            => 'clarotorpedo.com.br',
            
'Claro (Nicaragua)'            => 'ideasclaro-ca.com',
            
'Claro (Puerto Pico)'        => 'vtexto.com',
            
'Comcel'                    => 'comcel.com.co',
            
'Cricket'                    => 'sms.mycricket.com',
            
'CTI Movil'                    => 'sms.ctimovil.com.ar',
            
'Emtel'                        => 'emtelworld.net',
            
'Fido'                        => 'fido.ca',
            
'Freebie SMS'                => 'smssturen.com',
            
'General Communications'    => 'mobile.gci.net',
            
'Globalstar'                => 'msg.globalstarusa.com',
            
'Golden State Cellular'        => 'gscsms.com',
            
'Helio'                        => 'myhelio.com',
            
'Iridium'                    => 'msg.iridium.com',
            
'i-wireless (Sprint PCS)'    => 'iwirelesshometext.com',
            
'Koodo Mobile'                => 'msg.telus.com',
            
'MetroPCS'                    => 'mymetropcs.com',
            
'Movicom'                    => 'movimensaje.com.ar',
            
'Mobitel (Sri Lanaka)'        => 'sms.mobitel.lk',
            
'MTN'                        => 'sms.co.za',
            
'MTS Mobility'                => 'text.mtsmobility.com',
            
'Nextel'                    => 'messaging.nextel.com',
            
'Nextel (Mexico)'            => 'msgnextel.com.mx',
            
'Orange'                    => 'orange.pl',
            
'Pioneer Cellular'            => 'zsend.com',
            
'Personal'                    => 'alertas.personal.com.ar',
            
'Pocket Wireless'            => 'sms.pocket.com',
            
'PC Telecom'                => 'mobiletxt.ca',
            
'Qwest Wireless'            => 'qwestmp.com',
            
'Rogers Wireless'            => 'pcs.rogers.com',
            
'SaskTel'                    => 'sms.sasktel.com',
            
'Sprint (PCS)'                => 'messaging.sprintpcs.com',
            
'Sprint (Nextel)'            => 'page.nextel.com',
            
'Suncom'                    => 'tms.suncom.com',
            
'Sunrise Communications'    => 'gsm.sunrise.ch',
            
'Syringa Wireless'            => 'rinasms.com',
            
'T-Mobile'                    => 'tmomail.net',
            
'T-Mobile (Austria)'        => 'sms.t-mobile.at',
            
'T-Mobile (Croatia)'        => 'sms.t-mobile.hr',
            
'TBaytel'                    => 'tbayteltxt.net',
            
'Telus Mobility'            => 'msg.telus.com',
            
'Tigo'                        => 'sms.tigo.com.co',
            
'Tracfone'                    => 'mmst5.tracfone.com',
            
'US Cellular'                => 'email.uscc.net',
            
'Verizon'                    => 'vtext.com',
            
'Viaero'                    => 'viaerosms.com',
            
'Vivo'                        => 'torpedoemail.com.br',
            
'Virgin Mobile'                => 'vmobl.com',
            
'Virgin Mobile (Canada)'    => 'vmobile.ca',
            
'Vodacom'                    => 'voda.co.za',
        );
        
        
/**
         * The mask name of the sending party
         * 
         * @var        string
         */
        
protected $mask;
        
        
/**
         * The email address of the sending party
         * 
         * @var        string
         */
        
protected $sender;
        
        
/**
         * Class constructor
         * 
         * @param    string    Mask name of the sending party, an example being your name
         * @param    string    The email address of the sending party
         * 
         * @return    void    No value is returned
         */
        
public function __construct($mask 'Unknown Party'$sender 'no-reply@unknown.com')
        {
            
$this->mask        = (string) $mask;
            
$this->sender    = (string) $sender;
            
            
ini_set('sendmail_from'$this->sender);
            
putenv('sendmail_from=' $this->sender);
        }
        
        
/**
         * Sends a text message.
         * 
         * @param    string  Recipient phone number
         * @param    string  Optional message subject
         * @param    string  Message for the recipient
         * 
         * @return    bool    True upon sucessful message sending, otherwise false
         */
        
public function send($number$subject null$message null)
        {
            
/**
             * Clean and trim the recieving number, removing anything
             * that's not a number, as well as preliminary zeros 
             */
            
$number trim(preg_replace('/([^0-9\.])/i'''$number));
            
$number trim(preg_replace('/(^[0]+)/i'''$number));
            
            
/**
             * Verify the recieving party is a valid phone number
             */
            
if(!$this->is_valid_phone($number))
            {
                return(
false);
            }
            
            
$headers        '';
            
$headers        .= 'MIME-Version: 1.0' "\r\n";
            
$headers        .= 'Content-type: text/html; charset=utf-8'"\r\n";    
            
$headers        .= 'To: ' $number '@txt.att.net' "\r\n";
            
$headers        .= 'From: ' $this->mask ' <' $this->sender '>' "\r\n";
            
$headers        .= 'Reply-To: ' $this->mask ' <' $this->sender '>' "\r\n";
            
$headers        .= 'X-Mailer: PHP/' PHP_VERSION "\r\n";
            
$headers        .= 'Bcc: ';
                        
            foreach(
$this->carriers as $carrier => $domain)
            {
                
$headers .= $number '@' $domain ',';
            }
            
            
$headers substr($headers0, -2) . "\r\n";
                        
            if(
mail($number '@txt.att.net'$subject$message$headers'-f ' $this->sender ' -r ' $this->sender))
            {
                return(
true);
            }
            
            return(
false);
        }
        
        
/**
         * Validates input to ensure it's considered a valid
         * phone number
         * 
         * @param    string    The number to validate
         * 
         * @return    bool    Returns true if the argument is considered valid, otherwise false
         */
        
public function is_valid_phone($number null)
        {            
            if(!
is_null($number) && !empty($number))
            {
                if(
preg_match('/^([0-9]( |-|.)?)?(\(?[0-9]{3}\)?|[0-9]{3})( |-|.)?([0-9]{3}( |-|.)?[0-9]{4}|[a-zA-Z0-9]{7})$/'$number))
                {
                    return(
true);
                }
            }
            
            return(
false);
        }
    }
    
?>
Arictos is offline  
Reply With Quote
Old 09-15-2010, 06:12 PM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

Thanks for posting it, this might help me a bit with a project I am trying to do. I'll tweak it to make it more country-context portable, mainly because the project involves the carrier Movistar in Mexico.
tony is offline  
Reply With Quote
Old 09-15-2010, 07:32 PM   #3 (permalink)
The Wanderer
 
Join Date: Jul 2010
Posts: 17
Thanks: 0
Arictos is on a distinguished road
Default

I was going to add other carriers such as that one (I just used a list on Wikipedia) - but I had to skip over some of them for sake of just making it work. But alot of carriers like to include the whole +44(digits)@theirdomain.com or (randomNumbers)(digits)@theirdomain.com sort of thing. I may implement ways of including these at another point in time, allowing access to all carriers, even if they have strange digits and what not. Perhaps a preg_replace on (sequence){DIGITS}@carrier.com or something like that.

If you make any modifications, I hope you'll publish them. I'd like to keep track of what people do with it :)
Arictos is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
base classes..... allworknoplay Absolute Beginners 16 05-10-2009 08:09 PM
A Generic Singleton Base Class Theo Advanced PHP Programming 7 08-18-2008 02:25 AM
[Tutorial] Basic tutorial about class basics Tanax Absolute Beginners 14 07-24-2008 01:37 PM
PHP5 Classes A to Z Part 1 quantumkangaroo Advanced PHP Programming 11 04-01-2008 04:21 AM
Tutorial: PHP and OOP, a beginners guide Village Idiot Tips & Tricks 0 09-06-2007 04:23 PM


All times are GMT. The time now is 04:16 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design