How To Send SMS Texts From PHP.
http://rainnerlins.com/blog/php-sms-mailer
Tue, 01 Nov 2011 05:53:21 -0400
Download Share Comment
This post will show you how to use free SMS gateways available by all the major mobile carriers to relay your e-mail messages as a text message and have it delivered to a mobile phone.
Most of mobile carriers offer free Email To SMS gateways which can be used to forward simple text emails to mobile phones. The good thing is, the majority of these gateways are free and available to the general public for use. The format to use is [10DigitNumber]@GatewayAddress.
The way this works is the same as sending a simple e-mail message to someone and you can do this from any mail client or provider. In this case, i will show you how to send the message from PHP using the built in mail() function.
There is only one small down-side. Each carrier has their own unique relay address so you will need to find out what carrier the phone number belongs to before sending your message. I wrote a short little function to make things a little easier, but it's still very basic, feel free to add to it if needed..
SendSMS PHP Function
/*
SendSMS( CarrierName, TheMessage, ToMobileNumber, FromNumberOrEmail, GetDebugString )
*/
function SendSMS( $Prov="", $Msg="", $To="", $Re="", $Debug=false )
{
// cleanup incoming args and build array
$d = array();
$d['prov'] = trim( strtolower( strip_tags( html_entity_decode( $Prov ) ) ) );
$d['text'] = trim( strip_tags( html_entity_decode( $Msg ) ) );
$d['to'] = trim( preg_replace( "/[^0-9] /", "", strip_tags( $To ) ) );
$d['from'] = trim( strip_tags( $Re ) );
$d['addr'] = "";
// only major US carriers
switch( $d['prov'] )
{
case 'alltel': $d['addr'] = $d['to'].'@message.alltel.com'; break;
case 'att': $d['addr'] = $d['to'].'@cingularme.com'; break;
case 'cingular': $d['addr'] = $d['to'].'@cingularme.com'; break;
case 'boostmobile': $d['addr'] = $d['to'].'@myboostmobile.com'; break;
case 'nextel': $d['addr'] = $d['to'].'@messaging.nextel.com'; break;
case 'sprint': $d['addr'] = $d['to'].'@messaging.sprintpcs.com'; break;
case 'tmobile': $d['addr'] = $d['to'].'@tmomail.net'; break;
case 'uscellular': $d['addr'] = $d['to'].'@email.uscc.net'; break;
case 'verizon': $d['addr'] = $d['to'].'@vtext.com'; break;
case 'virgin': $d['addr'] = $d['to'].'@vmobl.com'; break;
}
// return a string with all the data for debugging..
if( $Debug ){ return ''.print_r( $d, true ).'
'; }
// check required data
if( empty($d['prov']) || empty($d['text']) || empty($d['to']) || empty($d['from']) || empty($d['addr']) ){
return false;
}
// send txt mail
$Send = @mail( $d['addr'], NULL, $d['text'], "From: ".$d['from']." <".$d['from'].">" );
return ( $Send ) ? true : false;
}
More Email to SMS Gateways
By now you should get the idea, you add a number in front of a gateway address and send away. If you want more free gateways, check out some of these links..
http://www.tech-faq.com/
http://www.mutube.com/
http://www.makeuseof.com/
User Comments
This section shows comments left for this post.
Sort:
Ascending |
Descending
Comment
Just fill in the form below to leave your comment as a guest.
Add a Comment
Blog Categories
Client Side Web Development Tips
Latest Work ( 12 )
This is a fully custom site, built on PHP and a custom CMS panel i did for adult..
Another previous version of this site that was built around 2010 to serve as a p..
This is a custom Flash, Portfolio mini-site i built for artist Aoife Hand. The c..
Tweets & Updates
My latest tweets will load here in just a second. In case they don't, you can head over to my twitter page @rainnerlins
http://rainnerlins.com/blog/php-sms-mailer
This post will show you how to use free SMS gateways available by all the major ..