How to Send Text Messages with PHP

How to Send Text Messages with PHP

Tutorial Details
  • Language: PHP
  • Difficulty: Beginner
  • Estimationed Completion Time: 30 minutes

Text messaging has become extremely widespread throughout the world — to the point where an increasing number of web applications have integrated SMS to notify users of events, sales or coupons directly through their mobile devices.

In this tutorial, we will cover the fundamentals of sending text messages with PHP.


Overview

Sending a text message (SMS) message is actually pretty easy.

Below is a simplified diagram of how a message can be sent from a web application to a wireless device.

We’ll break this down — one piece at a time:

  • The message is composed using a web application that is stored and executed on a HTTP server and then sent through the internet (“the cloud”) as an email message.
  • The email is received by a Short Message Service Gateway (SMS Gateway), which converts the message from an email message to a SMS message.
  • The SMS message is then handed to a Short Message Service Center (SMSC), which is a server that routes data to specific mobile devices.
  • The message is finally transmitted over the wireless network to the recipient.

Most wireless networks have a SMS gateway through which email messages can be sent as text messages to a mobile device. This is nice, because, from a developer’s standpoint, it is generally free—however, it is of course not a free service for the end user. Fees still apply to the recipient of the message and messages sent via email will be billed as a non-network text message.


Email to SMS

To send a SMS via email, you’ll generally require only two things:

  • The phone number or unique identifier of the mobile device you want to reach.
  • And the wireless network’s domain name (many can be found in this list of email to SMS addresses)

The following convention can be followed for most carriers:

phoneNumber@domainName.com

phoneNumber is the phone number of the mobile device to send the message to, and domainName.com is the address for the network’s SMS Gateway.

To send a text to Mr. Example, you could simply add 3855550168@vtext.com to any email client, type a message and hit send. This will send a text message to phone number +1 (385) 555-0168 on the Verizon Wireless Network.

For example, I’ll send a text message to myself using Gmail.

When my phone receives the message, it should look like so:

Pretty awesome!


PHP’s mail Function

Let’s take things a step further. Using the SMS Gateway, we can send a text message via email using PHP’s mail function. The mail function has the following signature:

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

You can read more about it here.

  • $to defines the receiver or receivers of the message. Valid examples include:

    • user@example.com
    • user1@example.com, user2@example.com
    • User <user@example.com>
    • User1 <user1@example.com>, User2 <user2@example.com>
  • $subject is rather self explanatory; it should be a string containing the desired subject. However, SMS do not require a subject.
  • $message is the message to be delivered. As mentioned in the PHP manual, “each line should be separated with a LF (\n). Lines should not be larger than 70 characters.”

To replicate the earlier functionality, we could write the following PHP code:

mail( '3855550168@vtext.com', '', 'Testing' );

A Test Drive

Let’s run a test with PHP to make that sure everything is setup correctly and that the mail function will, in fact, send a text message. Using the following code, we can run:

<?php

var_dump( mail( '##########@vtext.com', '', 'This was sent with PHP.' ) ); // bool(true)

?>

When my phone receives the message, it looks like so:

If you are getting an error, see the troubleshooting section.

As you can see in the image above, the message shows that it is from Gmail. This is because I route all my outgoing messages from my local server through that service. Unfortunately, as of this writing, I have been unsuccessful at altering the From header to reflect an alternate address. It seems that the email headers are stripped and replaced with headers prepared by the SMS gateway. If anyone knows of a workaround, please leave a comment and let the rest of us know!


Adding Usability

The Markup

With the basics out of the way, let’s take this idea and wrap a user interface around it. First we’ll set up a simple form:

<!DOCTYPE html>
 <head>
   <meta charset="utf-8" />
  </head>
  <body>
   <div id="container">
    <h1>Sending SMS with PHP</h1>
    <form action="" method="post">
     <ul>
      <li>
       <label for="phoneNumber">Phone Number</label>
       <input type="text" name="phoneNumber" id="phoneNumber" placeholder="3855550168" /></li>
      <li>
      <label for="carrier">Carrier</label>
       <input type="text" name="carrier" id="carrier" />
      </li>
      <li>
       <label for="smsMessage">Message</label>
       <textarea name="smsMessage" id="smsMessage" cols="45" rows="15"></textarea>
      </li>
     <li><input type="submit" name="sendMessage" id="sendMessage" value="Send Message" /></li>
    </ul>
   </form>
  </div>
 </body>
</html>

The Style

Next we’ll sprinkle in some CSS:

body {
 margin: 0;
 padding: 3em 0;
 color: #fff;
 background: #0080d2;
 font-family: Georgia, Times New Roman, serif;
}

#container {
 width: 600px;
 background: #fff;
 color: #555;
 border: 3px solid #ccc;
 -webkit-border-radius: 10px;
 -moz-border-radius: 10px;
 -ms-border-radius: 10px;
 border-radius: 10px;
 border-top: 3px solid #ddd;
 padding: 1em 2em;
 margin: 0 auto;
 -webkit-box-shadow: 3px 7px 5px #000;
 -moz-box-shadow: 3px 7px 5px #000;
 -ms-box-shadow: 3px 7px 5px #000;
 box-shadow: 3px 7px 5px #000;
}

ul {
 list-style: none;
 padding: 0;
}

ul > li {
 padding: 0.12em 1em
}

label {
 display: block;
 float: left;
 width: 130px;
}

input, textarea {
 font-family: Georgia, Serif;
}

This gives us the following simple form:


The Script

The most important part to this is the PHP script. We’ll write that bit of code now:

<?php

if ( isset( $_REQUEST ) && !empty( $_REQUEST ) ) {
 if (
 isset( $_REQUEST['phoneNumber'], $_REQUEST['carrier'], $_REQUEST['smsMessage'] ) &&
  !empty( $_REQUEST['phoneNumber'] ) &&
  !empty( $_REQUEST['carrier'] )
 ) {
  $message = wordwrap( $_REQUEST['smsMessage'], 70 );
  $to = $_REQUEST['phoneNumber'] . '@' . $_REQUEST['carrier'];
  $result = @mail( $to, '', $message );
  print 'Message was sent to ' . $to;
 } else {
  print 'Not all information was submitted.';
 }
}

?>
<!DOCTYPE html>
  • The script first checks to see if the form has been submitted.
  • If yes, it checks to see if the phoneNumber, carrier and smsMessage variables were sent. This is useful in the case where there may be more than one form on the page.
  • If phoneNumber, carrier and smsMessage are available and phoneNumber and carrier are not empty, it is okay to attempt to send the message.
  • The message argument in the mail function should be 70 characters in length per line. We can chop the message into 70 character chunks using the wordwrap function.
  • phoneNumber and carrier are concatenated and then the message is sent using the mail function.
  • If data is missing or it cannot be validated, the script simply returns Not all information was submitted.
  • Finally, mail returns a boolean indicating whether it was successful or not. The value is stored in $result in case I needed to verify that the message was in fact sent.

Note: The mail method only notifies whether the message was sent or not. It does not provide a way to check to see if the message was successfully received by the recipient server or mailbox.


The Final Code

<?php

if ( isset( $_REQUEST ) && !empty( $_REQUEST ) ) {
 if (
 isset( $_REQUEST['phoneNumber'], $_REQUEST['carrier'], $_REQUEST['smsMessage'] ) &&
  !empty( $_REQUEST['phoneNumber'] ) &&
  !empty( $_REQUEST['carrier'] )
 ) {
  $message = wordwrap( $_REQUEST['smsMessage'], 70 );
  $to = $_REQUEST['phoneNumber'] . '@' . $_REQUEST['carrier'];
  $result = @mail( $to, '', $message );
  print 'Message was sent to ' . $to;
 } else {
  print 'Not all information was submitted.';
 }
}

?>
<!DOCTYPE html>
 <head>
   <meta charset="utf-8" />
   <style>
    body {
     margin: 0;
     padding: 3em 0;
     color: #fff;
     background: #0080d2;
     font-family: Georgia, Times New Roman, serif;
    }

    #container {
     width: 600px;
     background: #fff;
     color: #555;
     border: 3px solid #ccc;
     -webkit-border-radius: 10px;
     -moz-border-radius: 10px;
     -ms-border-radius: 10px;
     border-radius: 10px;
     border-top: 3px solid #ddd;
     padding: 1em 2em;
     margin: 0 auto;
     -webkit-box-shadow: 3px 7px 5px #000;
     -moz-box-shadow: 3px 7px 5px #000;
     -ms-box-shadow: 3px 7px 5px #000;
     box-shadow: 3px 7px 5px #000;
    }

    ul {
     list-style: none;
     padding: 0;
    }

    ul > li {
     padding: 0.12em 1em
    }

    label {
     display: block;
     float: left;
     width: 130px;
    }

    input, textarea {
     font-family: Georgia, Serif;
    }
   </style>
  </head>
  <body>
   <div id="container">
    <h1>Sending SMS with PHP</h1>
    <form action="" method="post">
     <ul>
      <li>
       <label for="phoneNumber">Phone Number</label>
       <input type="text" name="phoneNumber" id="phoneNumber" placeholder="3855550168" /></li>
      <li>
      <label for="carrier">Carrier</label>
       <input type="text" name="carrier" id="carrier" />
      </li>
      <li>
       <label for="smsMessage">Message</label>
       <textarea name="smsMessage" id="smsMessage" cols="45" rows="15"></textarea>
      </li>
     <li><input type="submit" name="sendMessage" id="sendMessage" value="Send Message" /></li>
    </ul>
   </form>
  </div>
 </body>
</html>

Troubleshooting

Localhost Error

In order to use the mail function, you must have a mail server running. If you’re running this on a web host, you’re probably okay. But if you are unsure, I recommend talking to an administrator. This also holds true for personal machines. So if you get errors like..

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\sms\mail-test.php

…you will have to install and configure a mail server. This is out of the scope of this tutorial. However, if you are working on your local machine, switching to something like XAMPP might solve this problem. Alternatively, try installing Mercury Mail alongside WAMP, MAMP or on a LAMP (or SAMP or OAMP, etc.) system (that’s a lot of ‘AMPs’).

PHPMailer

Another option (which is the method I prefer) is to use PHPMailer. Below is an example of how to use PHPMailer to connect to Gmail’s SMTP server and send the message.

Using it is as simple as including a class in your script.

require 'class.phpmailer.php';

// Instantiate Class
$mail = new PHPMailer();

// Set up SMTP
$mail->IsSMTP();                // Sets up a SMTP connection
$mail->SMTPDebug  = 2;          // This will print debugging info
$mail->SMTPAuth = true;         // Connection with the SMTP does require authorization
$mail->SMTPSecure = "tls";      // Connect using a TLS connection
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Encoding = '7bit';       // SMS uses 7-bit encoding

// Authentication
$mail->Username   = "email.address@gmail.com"; // Login
$mail->Password   = "password"; // Password

// Compose
$mail->Subject = "Testing";     // Subject (which isn't required)
$mail->Body = "Testing";        // Body of our message

// Send To
$mail->AddAddress( "##########@vtext.com" ); // Where to send it
var_dump( $mail->send() );      // Send!

This should print out something along the lines of:

It may take a little more to set up the connection depending on your situation. If you’re planning on using Gmail, Google has provided information on connecting.


Conclusion

There are a myriad of methods to accomplish the task of sending a SMS through a web application. This method is really meant for low volume messaging (most likely less than 1,000 text messages per month) and developers looking to get their feet wet without forking out cash. Other options include:

  • Using a SMS Gateway Provider

    • Doing a Google search will return plenty of options.
    • Most SMS gateway providers include an API for sending messages through a web application.
    • You can usually sign up for service for a reasonable price, assuming you are planning on sending at least 1,000 SMS message per month.
    • You can rent a short code number.
  • Using a GSM modem

    • This can be a costly and slow way to do it, since you have to buy a modem and have a contract with a wireless network
    • You will also have to use the AT (Hayes) command set.
  • Use a direct connection to a wireless network, which will require some strong negotiating and a whole lot of money.

This tutorial is in no way a comprehensive review of sending tex messages with PHP; but it should get you started! I hope this tutorial has been of interest to you. Thank you so much for reading!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://vntx.net Graham

    There are plenty of much better ways to send real SMS without having to rely on email gateways. I’ve been using http://tropo.com for quite a few projects lately and they’re quite helpful when you run in to issues as well.

    • http://www.venture-ware.com/kevin Kevin Jensen
      Author

      I agree, there are better ways to send SMS. However, I just wanted to give a very simple introduction to developers that do not have funds to pay for a subscription to a SMS gateway provider, but still wanted to try out SMS with their applications.

  • http://www.arvag.net/ GaVrA

    Sooo tutorial on how to send email? Really? Or am i missing the point here… O_o

    • http://www.brianseitel.com Brian

      That was my first thought as well. Seriously? You’re giving a tutorial on sending email and then sensationalizing it by saying it’s for sending text messages? Gimme a break, Net Tuts.

    • Rafa

      GaVra,
      Yes, you are missing the point. He showed a sample on how to do it via email first, then shows you how to do what the email does via your own using PHP.

    • http://terrygfx.com Terrence Campbell

      The point is to use Email or simple PHP to send text messages to a phone. I do this everyday with my iPod Touch and it’s very fun. Except that it is annoying for T-Mobile users that have to confirm each message that came from an e-mail.

  • http://codemonkeydev.com/ Thomas Cannon

    This is an awesome article, I can’t wait to experiment with this in my spare time! I knew you could send a text via email, but I never considered doing so through a script. Thanks for connecting the dots!

  • Abhishek

    I had a tutorial planned on it since a long time. You got there before me! Anyways, nice :)

    • Aniketh

      Can you help me with this, Im trying via for airtel number from my gmail. Nothing is working though!

    • rajesh

      bring in your tutorial if it can tell me how to send a text to any mobile no in india at no cost.

  • http://30.com.au Steve

    Thats a cool tut.

  • http://mimrankhan.com Imran Khan

    lot’s of alternative ways of sending SMS available. Nevertheless it’s a good tutorial.

  • http://www.thedevelopertuts.com Bratu Sebastian

    There is also a tutorial on sending sms with CodeIgniter and a mobile gateway created by me here, if anyone is interested:

    http://mobile.tutsplus.com/series/create-an-sms-signup-form/

  • http://www.samuca.com Samuel

    I wrote a solution years ago, in portuguese, and throw a GSM modem attached to your computer.

    http://www.samuca.com/sms/enviando-sms-atraves-do-php.php

    Cheers.

    • http://www.facebook.com/juliomindigo Julio de Almeida

      Pois é Samuel, lí seu artigo a um tempo atrás. Pensei que esse artigo da envato pudesse me ajudar mas infelizmente no Brasil ainda teremos que nos submeter as condições absurdas que as operadoras e a ANATEL nos impõe para esse tipio de aplicação.

      Abraço.

  • http://bobby-marko.com Bobby

    Twilio ( http://www.twilio.com/ ) provides a nice api for sending and receiving SMS similar to Tropo.

    • http://www.rebatesense.com RebateSense

      Twiliio charges $$ for the service, even though it’s very nominal it is still something to pay. Other than that Twilio is the way to go I guess.

    • http://www.venture-ware.com/kevin Kevin Jensen
      Author

      I will have to try Twilio. Thanks for the link, Bobby!

  • James

    Just a shame I can’t find the correct address format for 3(UK) :(

    • http://www.venture-ware.com/kevin/ Kevin Jensen
      Author

      If you are on the network in question, send yourself an email from your mobile device. That should give you the correct address format.

  • creapptive

    Damn, this tut destroys my day. Worst tut ever in nettuts. Puking…. : (,)

    • http://www.jeffrey-way.com Jeffrey Way

      Why?

      • http://www.lkrvk.com laxmi kanth raaj

        coz it doesnt work in other networks apart from version and it doesnt really works with that number@vtext.com

        Laxmi kanth raaj

      • Anthony

        Because he’s lacking the decency and manners to gracefully accept that while he may not have found this article interesting, others might – like me for example….nice tut!

      • Jonas

        While creapptive may not have expressed it very nicely, he’s got a point: The whole tutorial is basically an introduction to sending email with PHP, which I’m sure most people here know how to do (and if they don’t, all they need is a link to http://php.net/manual/en/function.mail.php).

        The fact that you can use email to send texts is useful information, but it’s such a short tip that it could be delivered via a Twitter message. In other words: If the article can be boiled down to a single sentence (“did you know you can use xxxxxxx@yourtelcom.com to send texts through PHP’s mail() function?”), then there’s not much point in writing a whole tutorial.

      • creapptive

        ditto Jonas.

    • http://www.venture-ware.com/kevin Kevin Jensen
      Author

      Reading about sending email to a SMS Gateway makes you puke. Hahaha! That’s crazy.

      • http://michael.theirwinfamily.net Michael

        Haha… that made me laugh! Glad to see the humor! :-)

      • creapptive

        Yeah same as seeing a pig.

    • Vomit Eater

      Mmmm… Puke

  • http://webkicks.dotink.org Matthew J. Sahagian

    If you have google voice you can also use this very simple API to send texts via it, although google is now limiting the amount of texts you can send per day:

    http://code.google.com/p/phpgooglevoice/

    It seems to depend on number of recipients too though, so perhaps if you were just using this to send updates from your own site or something like if someone posts to comments or whatever, etc…

    Another alternative that works similarly, however, is just to make a twitter account for your website, and then post things to that like if someone comments, etc, and you can follow that on your phone.

    • http://www.electrictoolbox.com/ Chris Hope

      That’s how I do it. I have a private Twitter account which I send DMs to and they’re sent by SMS to my mobile. I did use it for monitoring web servers but it was a bit unreliable for prompt delivery at one stage.

  • http://butenas.com Ignas

    Hmz… Not the best way to send SMS… Topic was promising but it ended up with jus simple script to send the email… Better way is just to find provider who lets you to use API and then you just making the request with parameters it requires… Done it few times and it’s even easier.

    • http://www.electrictoolbox.com/ Chris Hope

      I absolutely agree. From the title I thought it was going to be an interesting tut maybe hooking into a particular SMS provider’s API (or something along those lines) and it turns out to be a “how to send email with PHP” type tut instead. Quite disappointed with the quality of this really.

  • http://blog.icodeu.com php

    that is what i want

  • Tom

    Nice, Ive always knwon this was possible but never got it to work with UK operators ie. [number]@o2.com/co.uk doesnt work

  • http://www.chezeric.biz Eric

    Works only in the US or in Canada. In the rest of the world it’s impossible : sending a text via email has been locked by carriers. The only way to send email through PHP is to connect via the API provided by the carriers and some third-parties.

  • http://onlineqrlab.com/ Abid Omar

    How to send an SMS with a Gate Way

  • Rob

    seriously, using $_REQUEST is terrible practice especially when you know the content is coming from $_POST. There is a total lack of sanitisation of all the variables and a complete lack of appreciation for best security practices

    • http://funkall.com Dale Hurley

      HA!

      You do realise that you can use Web Developer Toolbar to change form methods from POST to GET or GET to POST???

      Request is actually smarter and allows for MVC and code reuse. For instance you might want to turn your web app into a web service and receive data via GET variables even though in the past you used POST. I am slowly in the process of turning sites into using REQUEST.

      • sprky0

        I’m sorry to be negative Dale, but that is a foolish response. This tutorial provides some good basic info on how to target SMS via email, but it really should address the security implications of what is going on. In terms of the backend component, essentially what this tutorial describes is how to write an open mail relay with an HTTP wrap, with no sanitzation, rate limiting, or security of any kind. If implemented as is, you leave your server wide-open to abuse by spammers or worse.

        If you don’t grasp that yet, then … my apologies to your clients. I hope that you take a more serious view of security in the future.

      • Rob

        wow, just wow. I hope you have your source code in a VCS somewhere so you can revert it when you realise how foolish that is.

  • Derek

    Will this work for us in the uk?

    seems a bit strange since we don’t pay to recieve messages, only when we send them. how would this work?

  • http://www.j2designstudios.com Jim

    I figured this out last year on a whim. Worked great. Never thought about submitting it as a tut. I should probably put one together!

  • http://www.twitter.com/phillpafford Phill Pafford

    Well this is one option and you could improve it with using a drop down for the carrier names, this would ensure the proper spelling. As well I would also add country as a drop down as carriers often have different email gateway addresses for different countries. Also carriers offer SMS and MMS email gateway addresses which could be another option as well if one wanted to send photos or larger than the 140 (which most carriers limit on) character limitations.

    There are a couple of other services which I have seen mentioned here as well like:

    Twilio and Google Voice.

    There are also ad supported free text message services like Zeep Mobile as well. They have an API that allows you to use their service for free but they place an ad at the end of you text message.

    All of these have there own place but if you truely wanted to do SMS/MMS text messaging you should go with an aggragator like http://www.openmarket.com and get your own short code. I know there are cheaper solution as you could use a shared short code as well.

  • Khaled

    did you try ribbit service

    http://developer.ribbit.com

  • http://www.ohiowebdesignguy.com Josiah Sprague

    Very simple tut, but it shows how much you can accomplish using basic PHP and a little bit of thought. Third party APIs may be more powerful, but I think the point is that adding an SMS functionality is as simple as sending email and there is no need to over-complicate it or rely on a third party service for a simple application.

    To make it even more straightforward for the end user, you could skip asking them which carrier, and just send the email to phonenumber@eachcarrier.com, yeah, you’ll get a few bounced messages, but if you’re designing a simple application that’s not going to have a lot of users, I don’t think that’s necessarily a bad tradeoff.

  • http://www.chimply.net Dieter

    it is generally free—however, it is of course not a free service for the end user. Fees still apply to the recipient of the message and messages sent via email will be billed as a non-network text message.

    So that means if you know their domainname you can really ruin someone’s day by sending them tons of messages? Evil!

    That kind of leads me to another question, how can you know a client’s domainname? My guess is you have to ask them to select a network from a list and then assign the domainname to it from a database? Do the available API’s auto detect a client’s domainname?

    I really like the SMS via PHP idea, it’s useful to keep client’s updated on changes and such. Maybe a more detailed tutorial in the future perhaps?

    Thanks, Kevin

    • http://www.venture-ware.com/kevin/ Kevin Jensen
      Author

      Thanks, Dieter and you’re welcome. I do believe you could build a script that could spam a wireless network. However I would imagine big networks like AT&T or Verizon would have methods of ignoring spam as not to overload the network.

      In regards to knowing the domain name for the SMS gateway-Sending the text message via email you do have to know the network’s domain. If you are using a SMS gateway provider’s API they generally do the foot work for you and track down the network for you. It works a lot like DNSs do for the internet.

      I thought about including AT command in the tutorial but felt it was out of the scope of the tutorial as this is NetTuts+. Perhaps I could do it for MobileTuts+. =D

  • http://tropo.com Adam Kalsey (Tropo)

    Sending a text message from PHP with Tropo:

    <?php
    message(“Do you have Prince Albert in a can?”, array(‘to’ => ’12125551212′, ‘network’ => ‘sms’));
    ?>

    See https://www.tropo.com/docs/scripting/sending_text_messages.htm

    And it can do voice, instant messaging, and Twitter, too.

    Using the carrier’s email gateway works fine for some uses, especially one where it’s not important if your message is delivered quickly or at all. Carriers place very low priority on smtp traffic and will drop or delay messages as needed. They also will block the IPs of mail servers they consider abusive, silently dropping all messages that come from those servers.

    Because you have to know the user’s mobile carrier up front, you’ll be unable to deliver a message if the user changes their carrier or doesn’t know it. And you’d be surprised by the number of people who don’t know their carrier. Lots of people that don’t pay their own mobile bills have no idea who their carrier is. If mom and dad or your company pays it, you may not know. And if the user changes carriers but forgets to notify you, your messages will be sent to the wrong carrier, where they’ll ignore them.

    Do you need two-way messaging? Should your users be able to reply to the SMS and have it delivered to you? Then email gateways won’t work for you.

    Email gateways and GSM modems are great for DIY applications and work well for lots of uses, just like a spare computer under your desk can serve as a great web server for low-traffic sites. SMS gateways and APIs are there when you need more.

  • http://www.shay.co/ Shay Ben Moshe

    Very nice article!
    However, I couldn’t find any way to send SMSs within Israel’s network for free…

  • http://www.twitter.com/netblonde netblonde

    creepily easy!

  • http://www.mutatedcreativity.com Jeremy

    Also to send a SMS text message that the recipient can reply to, you have to add the fifth parameter. So it would look something like this:

    $result = @mail( $to, ”, $message, ”, “-freply@example.com” );

    Although I’ve never played with an empty header string before. When the user replies to the text, ‘reply@example.com’ should receive the email. :)

  • chichibek

    este es un tema que interesa, porfavor depurarlo y continuar con el asunto…. gracias

  • http://www.zipbox.co.uk Stewart

    There are certainly better solutions for sending SMS but this is a nice simple script. Good for learning if nothing else. Cheers.

  • Braden

    Thanks for the tutorial.

    Question: Does anyone have a good recommendation for the opposite? I would like to be able to set up sending an SMS to a web app.

    I’ve seen a few, just trying to find out which is best.

  • http://christiansouth.com Christian South

    Am I the only one that is thinking ‘… Wow… a flip phone’?

  • Jordy

    Some idea how to send text messages to Spain mobiles?

  • http://lavideo.eu bleach

    very simple, i like this tuto!

  • Selcuk

    Thank you.

  • http://www.emailbeauty.co.uk Ash

    It is good to know that it is relatively simple to incorporate SMS sending into a SaaS application for example. I bet the CPM is high this way ?

  • http://TacticalMarketingLabs.com Brett Relander

    Thanks for the info. I really find the article and comments very helpful in evaluating options and determining the best course of action. Thanks for sharing. Have a great day!

    @BrettRelander

  • David

    It would be interesting to see a script where you could send an SMS text to a group. I would find this very useful. Would it be possible to keep a group list in an sql database that the script could pull from?

    Anyone have ideas or places to look for something like that?

  • Max

    Kevin Jensen how do you configure you localhost to send gmai email

  • Attila

    A piece of free PHP class to send SMS messages using SMSBug:
    http://w3net.eu/2007/10/31/send-sms-messages-from-your-website-through-smsbug-gateway/

  • http://www.rcgelverio.com ryan

    great tutorial! interesting

  • http://gumz-ex-press.com/ Gumz

    Very interesting… want to try…

  • http://www.sosochat.com/ Milford

    Never thought that it is possible to send sms through a script .Appreciate your in-depth knowledge in PHP and nd such an informative post. Keep up the good work Kevin!

  • http://www.e11world.com e11world

    Maybe this is a dumb question but I tried just testing this and not really sure what the carrier field is suppose to have?? the email?? This does seem to have a bunch of security issues and probably not the concern here but still a good idea even though there are other options.

  • http://anealkhimani.com Aneal

    Interesting. Gonna pair PHP up with my Arduino to send me txt messages when my postal mail arrives.

  • http://www.techendeavour.com Rahul Aggarwal

    There are many ways of sending SMS but I appreciate for your effort and will give a try.

  • http://funnyfacebook.org gecko

    this article suppose to be not ho to send text message with php but how to send email with PHP.

    We can use now sms or Gammu for this

  • http://www.theinternetoncomputers.com Matthew Littlehale

    You can set the “from” header so that it looks like it is coming from anywhere by using the -f additional parameter in php mail. For example:

    mail(‘######@cellphone.com’, ‘subject_empty’, ‘this was sent with php’, null,
    ‘-fwhereeveryouwantit@tocomefrom.com’);

    That used to work at least, it still should.

  • mustafa

    hi nice post

    im developing an asp.net app

    and i wnt 2 send an sms from that app free of cost
    is it possible
    can u help me plzzz thnks

  • http://www.bina.com.tr söve

    very simple, i like this tutorial