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

Receiving MMS messages


First, let's learn how to receive picture messages. This is similar to how we receive text messages; the only difference is that picture messages using MMS also include a field named MediaUrl , which contains the URL that was attached to the message.

We will begin by setting up a file named listener.php, which is where we will configure Twilio to send our messages. This script will store all incoming messages in a MySQL database and download the attached image locally. Then we will set up a file named messages.php, which will display the message along with the image.

Getting ready

The complete code for this recipe can be found in the Code/Recipe1/ folder.

How to do it…

Let's set up our listener.php file to store all incoming messages and messages.php to view messages we've received.

  1. Upload config.php to your web server with the following code:

      <?php
        $accountsid = '';  //  YOUR TWILIO ACCOUNT SID
        $authtoken = '';  //  YOUR TWILIO AUTH TOKEN
        $fromNumber = ...