How to Send a Free SMS Using PHP

by Chris Davis
fotohandy image by Marcus Scholz from <a href=''></a>

Short message service (SMS) messages, also known as text messages, have become the preferred way of communication for many people. They offer email's benefit of mass messaging, but also have the additional benefit of being received nearly instantly. What many people don't know is that SMS messages can actually be sent through HTTP in the same way that an email is, meaning that PHP Web applications can be made that send SMS messages to users for free.

Step 1

Select the phone number that the message will be sent to. This could be acquired from a database, file, or HTTP headers. For this example, we will assume it was sent through HTTP using the GET method.

Step 2

Append the carrier's email domain to the end of the number. This example uses only three possible carriers.

Step 3

Set the body of the message. Remember that most mobile carriers only allow messages of 140 characters or fewer to be sent and received via SMS.

Step 4

Set the message's headers. You will need to set a "From" header. You can set it to a standard email, or to the number of your mobile device (as long as you append the proper domain to the end). Any other headers are optional and may not even be read by the carrier's server.

Call PHP's built-in mail function to send the message. Leave the second parameter blank, since SMS messages don't have a subject field.


  • Users will need to provide both their phone number as well as their carrier before you will be able to send them SMS messages.
  • Mobile customers in some countries cannot receive messages sent this way. Be sure to send your users a confirmation message when they give you their data to ensure that they are properly receiving messages. In order to send SMS to these users, you will need to pay for an SMS gateway.


  • PHP's mail function returns a boolean value, so your script can check to see if the message was sent successfully.


Photo Credits

About the Author

Chris Davis has been writing and editing since 2001. He has written for Elinon Online and written and edited content for the Oaks Fellowship. Davis studied computer science at Texas A&M University-Commerce and is now working on a Bachelor of Arts in English at Southwestern Assemblies of God University.

More Articles