Get Started

Twilio SMS Quickstart

Replying to Text Messages

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
    <?php
    
    	// make an associative array of senders we know, indexed by phone number
    	$people = array(
    		"+14158675309"=>"Curious George",
    		"+14158675310"=>"Boots",
    		"+14158675311"=>"Virgil",
    	);
    
    	// 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";
    ?>
    <Response>
    	<Message><?php echo $name ?>, thanks for the message!</Message>
    </Response>
        

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 »