Skip to content
Advertisement

How to Reply to Inbound SMS with MMS in WordPress PHP Twilio

Using WordPress PHP and Twilio, how can I reply to an inbound SMS with a message that contains media. Specifically I want to reply to inbound messages with an image. I’m having trouble finding a way to add media to the response. How do I add an image to the format used below?

function trigger_receive_sms($request) {
  echo header('content-type: text/xml');
  echo ('<?xml version="1.0" encoding="UTF-8"?>');
  echo ('<Response>');
  echo ('<Message>Hello there, did you get the image?</Message>');
  echo ('</Response>');
}

Used this guide for overall foundation: https://www.twilio.com/blog/2017/09/receive-sms-wordpress-php-plugin.html

Advertisement

Answer

Twilio developer evangelist here.

To respond with media you need to nest <Media> and <Body> elements in your <Message>. <Media> should have a URL to the media you want to reply with.

function trigger_receive_sms($request) {
  echo header('content-type: text/xml');
  echo ('<?xml version="1.0" encoding="UTF-8"?>');
  echo ('<Response>');
  echo ('  <Message>');
  echo ('    <Body>Hello there, did you get the image?</Body>');
  echo ('    <Media>https://demo.twilio.com/owl.png</Media>');
  echo ('  </Message>');
  echo ('</Response>');
}

Let me know if that helps at all.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement