PHP Quickstart: Replying to Text Messages By Name

Ok, we've said "Hello" to the mobile monkey, but what if the monkey wants to say, "Thanks" back? Let's lookup the sender, and thank them for sending us a message by name if we can:

    • quickstart/sms/sms-reply.php
      	// make an associative array of senders we know, indexed by phone number
      	$people = array(
      		"+14158675309"=>"Curious George",
      	// if the sender is known, then greet them by name
      	// otherwise, consider them just another monkey
      	if(!$name = $people[$_REQUEST['From']]) {
      		$name = "Monkey";
      	// now greet the sender
      	header("content-type: text/xml");
      	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
      	<Message><?php echo $name ?>, thanks for the message!</Message>

    If you add your phone number and name to the people array you will get a personalized SMS thank-you from your app.

    Next: Tracking Conversations »