Book Image

Twilio Cookbook: Second Edition

By : Roger Stringer
Book Image

Twilio Cookbook: Second Edition

By: Roger Stringer

Overview of this book

Table of Contents (20 chapters)
Twilio Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Sending SMS messages in a phone call


We've handled all other sorts of SMS messages, but what about sending an SMS during a phone call? This recipe will send an SMS message to anyone who calls our phone number.

Getting ready

The complete source code for this recipe can be found in the Chapter6/Recipe7/ folder.

How to do it...

This recipe will show you how to build a simple app that will send an SMS to the person who called your phone number.

  1. Upload sms.php to your server as follows:

    <?php
      $people = array(
           "+14158675309"=>"Curious George",
           "+14158675310"=>"Boots",
           "+14158675311"=>"Virgil"
      );
      if(!$name = $people[$_REQUEST['From']]) {
          $name = "Monkey";
      }
      header("content-type: text/xml");
      echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    ?>
    <Response>
        <Say>Hello <?php echo $name ?>.</Say>
        <Sms><?php echo $name ?>, thanks for the call!</Sms>
    </Response>
  2. Finally, you have to point your...