Send text message using php

Kids these days, I tell ya. All they care about is the technology. The video games. The bottled water. Oh, and the texting, always the texting. Back in my day, all we had was…OK, I had all of these things too. But I still don’t get the volume of texts that I hear my younger female cousins send. Thousands and thousands of them each month. WTF are all of these texts for? Here’s a thought:

omg did you hear?
no wut
omg i can’t believe you didn’t hear
lol tell me!
jenny and mark were holding hands
omfg does john no?
ok i made it up, ur so lame

Riveting. Jokes aside, text messaging can be an extremely useful way to get out of calling that person you hate calling communicate quickly and efficiently. Many websites are now offering text message notifications instead of email notifications, which can be nice in the case of time-sensitive information. After a bit of research, I found out how easy it was so send text messages using PHP, so that I can integrate text messaging into my apps! Let me show you how!

The Methodology

Unbeknownst to me, sending text messages can be as easy as sendmail, because you can send your text to an email address and it will be delivered. There are two pieces of information you must know: the phone number and the carrier’s text message email domain. Needing to know the recipient’s carrier is not ideal, but necessary.

Phone companies have internal lookups for phone carriers but developers like you and I don’t get access to them, so knowing the carrier is a must. To send a text message, you email{phoneNumber}@{carrierDomain}.

The PHP

PHP’s provided method for sending emails is the mail function. Its usage is quite simple:

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

Using the mail function and the text message email format, sending a text message is as easy as:

// Call Gary

mail("09988998822@txt.rel.net", "", "You have a message!", "From: Root Node \r\n");

Note that no subject line is provided, and more importantly, a FROM header is within the last parameter so that the recipient knows where the text message has been sent from.

Who knew it was that easy? I always assumed text messaging had its own protocol and all that magic. Apparently not! Spend a few minutes playing around with text messaging yourself; it’s one of those things that’s both neat to do and useful!

Sending mail from myhost/gmail

When I was new to php I was sending mail using php’s basic mail() function, but later I came across phpMailer class, which can be used to send mail using any host of your choice (Gmail, for example).
This is an simple code script needed to send an mail using your host and login details.

<?php
//including phpMailer class
require_once("phpmailer/phpmailer.php");
//creating object for phpMailer class
$mail = new PHPMailer();
IsSMTP();
$mail->SMTPAuth = true;
$mail->From = "Your Email";// example stufflies@domain.com
$mail->FromName = "Your Name";// example Stuff Lies
$mail->Username = "Your Username"; //example stufflies, for gmail username@gmail.com
$mail->Password = "Your Password";//example *******
$mail->Host = "Your Host name"; //example for gmail smtp.gmail.com
$mail->SMTPSecure = "ssl";//ssl/tls
$mail->Port = "Your Host port number";//example for gmail 465
$mail->AddReplyTo("Your Email","Your name");
$mail->AddAddress("Recepient email address","Recepient name");
$mail->IsHTML(true);
$mail->Subject = "Your subject"; //example Stufflies phpMailer
//$mail->AddAttachment("temp file", "filename");//remove comments if attachment required
$mail->Body = "Your message"; //example Testing message from stufflies.wordpress.com
if($mail->send())
{ echo "Mail sent"; }
else { echo "Sending failed"; }
?>

The code uses phpMailer class which can be downloaded from phpMailer Download.

Although every effort is made to make this code simple , yet if any issue arise feel free to comment or contact me.

White Screen of Death

Right now some situations (parse errors, undefined function call, no more memory) in PHP result in fatal error – which means the engine can not continue with the request beyond this point. From the user point of view, this often results in a blank page. I wonder if it would be possible to have standard recovery mechanism that would allow the PHP engine on fatal error to enter some kind of “recovery mode” when it would output some very basic page saying “ok, I have some problems here, but don’t panic and just tell my programmer to fix the code”. It won’t give much info probably but it would allow production sites display nice message to the users instead of the boring snowfield panorama it displays now (that is if the administrator was smart enough to set display_errors to off).

Maybe it should allow only fixed HTML, or maybe some kind of “request recovery” mode which would create some “recovery mode” sub-request when it would allow to do more – like send emails to webmaster. This may need some creative thinking but the main idea is to move away from the snowfield thing.

Working on Sunday

Here I am, working on a glorious Sunday. The skies are blue which means I should be doing one of the following things
Riding my bike
Eating IIM Maggie
Playing
Checking out good food somewhere
Cooking/Baking
Having picnic with some one.

But, what’s this…
Here I am in office working….

Royal enfield classic 500

The Royal Enfield Desert Storm is another variant of the Classic 500. The Desert Storm as the name suggests is a bike that ignites pride and excitement of the battlefield in the hearts of the rider. The Desert Storm has been described as a rebel with a penchant of looking different among a crowd of similar bikes.

The new leisure bike’s design has been inspired by the erstwhile Second World War army bikes. The bold and macho look redefines class. Its pale color scheme along with the matt paint job is in a way a camouflage. The body colored thigh pads also add to the look.

The Desert Storm’s technical specifications are similar to that of the Classic 500 and the Classic Chrome 500. It is also powered by the 500cc Twin Spark unit construction engine that develops 27.2bhp.

Talking about the new bikes, Dr Venkatesh Padmanabhan, CEO, Royal Enfield said, “When we launched the Classic in November 2009, we had not imagined in our wildest dreams that this new product would occupy almost 40% of our total sales within a year of its launch. During this time we have feverishly engaged ourselves in burnishing this gem. The fruits of this labor are now manifested in the Classic Chrome and Desert Storm.”

Classic Chrome and Desert Storm, being limited edition products, would be available at select brand stores and dealerships across the country.