How to Send Free Text Messages Using PHP

I am currently working on a large project and part of the project is to send simple text message notices using PHP.  Our client had looked into a number of expensive services to send simple SMS messages but most were cost prohibitive for a start-up venture.

As usual, I was not satisfied paying for something that I should be able to do on my own. So I started thinking about how the messaging systems worked and realized that we could just use the carriers built in email addresses for MMS messaging.  This is a great, cost effective method for sending text messages but it does require that you know the user’s carrier for the message to be successfully delivered.  In our case, we are able to ask for that in the web form which we are using to collect the user’s phone number but it may not work for every application. 

Basically the solution is to send an email using the built in mail function in PHP or any common method of sending email.  The email address you would send to would be the 10 digit mobile number followed by the carriers specific email address. (A list is included below)

Email addresses for the primary U.S. based cell phone carriers:
Alltel = xxxxxxxxxx@message.alltel.com
AT&T = xxxxxxxxxx@mms.att.net or xxxxxxxxxx@txt.att.net
Boost Mobile = xxxxxxxxxx@myboostmobile.com
Centennial Wireless = xxxxxxxxxx@myblue.com
Einstein PCS = xxxxxxxxxx@einsteinmms.com
Nextel = xxxxxxxxxx@messaging.nextel.com
Sprint = xxxxxxxxxx@messaging.sprintpcs.com or xxxxxxxxxx@pm.sprint.com
T-Mobile = xxxxxxxxxx@tmomail.net
US Cellular = xxxxxxxxxx@mms.uscc.net
Verizon Wireless = xxxxxxxxxx@vtext.com
Virgin Mobile = xxxxxxxxxx@vmobl.com

The simple PHP code to send the email:

<?PHP
     //SUBJECT AND BODY OF EMAIL SHOULD BE LESS THAN 160 CHARACTERS TOTAL
     $subject = "Text Message Subject";
     $message = "Text Message Content"; 
 
     //SENDS TEXT MESSAGE TO 503-869-4212
     mail("5038694212@txt.att.net",$subject,$message,"From: email@site.net");
?>

No related posts.

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

I am not spam. I have a question. Where does this php file go and where does it get activated from? Do I just load it on the server and then call it by URL?

Ryan,

Thanks so much for posting this. I am doing a project for a start-up and ran into the same problem. This is so great to know about!

Thanks again for sharing.

Ryan, thank you for putting this up. I looked at all the paid services and they simply did not make sense to me. Anyway, appreciate it.

Thanks for the big list of providers addresses. We created a similar concept using a linux distro and a smtp app for our senior design project at engineering school. We used a sbc, hooked up some sensors, and when certain sensors where tripped, the linux distro built for the sbc would text message proper phones. I wrote the texting script using bash, but it can be done in php, java, c/c++, etc. Just heads up to anyone thinking about this. We used the smtp client to forward text messages through gmail. the google people really didn’t like it. Twice I had to re-authorize my account (I guess they thought I was a spammer). So if you do this, make sure your email service/server knows what is going on. Also, it is really easy to “text bomb” phones. Make sure you do some validation/limiting to prevent this. I found it funny when my buddy got about 300 texts at $.10 each while we were testing the complete system. Just think what it would of been if I called the script in a while(true) loop. :)

some info on what to do with the php would be most helpful. it costs me 50c a pop to send txts to my fiance in the states. thanks.

Thanks for this post, I am currently working on a project where this will prove to be usefull.

How?………..

Anyway to do this w/out the FRM: and MSG: showing up? I set everything to null and it comes out like..

Text:FRM:nobody
MSG:

I’d like to just send a text w/out any of the “Text:”, “FRM:”, and “MSG:”. Ideas?

The FRM: and MSG: are put in by the cell phone company so there is no way to remove them (that I am aware of) using this method. I believe to send a blank message you would need to use a true text messaging gateway service. Note, you will find that not all cell companies include the FRM: and MSG: elements and some will actually ignore the value you input for subject all together.

Excellent. Thanks for the post and information on how to do this.

hi guys this web site works
http://www.webdeveloper.com/forum/showthread.php?t=170285
i try this on my server and it work fine

hi, pls any 1 send me complet scirpt? :(

I used you code:

It worked great.

However on $message instead of sending a message like you did I need to so a php calculation like

$day = date (j);

$message = $day * 75;

and then send the $message

This will be an ID code that will change daily.

hi friend,
i from india(tamilnadu). i used in airtel. I tried to this code . but the message didn’t send. I don’t know . what a problem.
airtel provider email address is xxxxxxxxxx@airtelchennai.com.
please send the script .

Hey Ryan,
This post is the best so I tried to subscribe via email but I encountered an error. Just for the heads up!
Thanks,
Joe!

Boss I was looking up to do this and didn’t know I clicked on your link..hahahahhaha nicely done.

If you send the txt with a simple question (Movies on Tue @ 7pm, going?), how would I collect the replies?

“Where does this php file go and where does it get activated from? Do I just load it on the server and then call it by URL?”- mahvin

i also would like to know the answer to this question-i see there is no response to it above.

i placed the script in my website source code but am new at all of this and need to know more info about it, such as how it can be activated-thank you

Nicole:

I loaded the php script onto my server and then called it by URL. Use a php extension on the file.

So… this assumes your database has fields of ‘phone’ and ‘carrier’

start PHP ….

$phone_carrier = “”;
$phone_no = “”;
$sms_enabled = “”; // add to accountOptions_table 0 (no) or 1 (yes)

if ($sms_enabled == 1) {

//// Account Options section
$sql = mysql_query(“SELECT * FROM table_data_is_stored WHERE id=’$id’ LIMIT 1″); // query the member

while($row = mysql_fetch_array($sql)) {

$phone_no = row['phone'];
$phone_carrier = row['carrier'];

} //end while loop
////
// determine carrier code to use
////

if ($phone_carrier = Alltel) { $phcr = @message.alltel.com }
else if ($phone_carrier = AT&T) { $phcr = @txt.att.net }
else if ($phone_carrier = BoostMobile) { $phcr = @myboostmobile.com }
else if ($phone_carrier = Centennial Wireless) { $phcr = @myblue.com }
else if ($phone_carrier = Einstein PCS) { $phcr = @einsteinmms.com }
else if ($phone_carrier = Nextel) { $phcr = @messaging.nextel.com }
else if ($phone_carrier = Sprint) { $phcr = @pm.sprint.com }
else if ($phone_carrier = T-Mobile) { $phcr = @tmomail.net }
else if ($phone_carrier = US Cellular) { $phcr = @mms.uscc.net }
else if ($phone_carrier = Virgin Mobile) { $phcr = @vmobl.com }
else if ($phone_carrier = Verizon Wireless) { $phcr = @vtext.com }

////
// end determine carrier code
////

//SUBJECT AND BODY OF EMAIL SHOULD BE LESS THAN 160 CHARACTERS TOTAL
$subject = “Text Message Subject”;
$message = “Text Message Content”;

//SENDS TEXT MESSAGE TO 503-869-4212
mail(“$phone_no$phcr”,$subject,$message,”From: email@yourdomain.com“);

} // end if condition

end PHP

heres a list of some of those email addresses mentioned above. Its an older list but may be helpful

http://www.codingforums.com/showpost.php?p=796277&postcount=3

Leave a comment

(required)

(required)