SUPPORT.TWILIO.COM END OF LIFE NOTICE: This site, support.twilio.com, is scheduled to go End of Life on February 27, 2024. All Twilio Support content has been migrated to help.twilio.com, where you can continue to find helpful Support articles, API docs, and Twilio blog content, and escalate your issues to our Support team. We encourage you to update your bookmarks and begin using the new site today for all your Twilio Support needs.

Forwarding SMS Messages to your Email Inbox

Incoming Twilio Programmable SMS Messages can be forwarded to an email inbox with just a few lines of code. Here is an example to get you up and running quickly.

Forward Incoming SMS Messages using Webhooks

To host your own code as a Twilio webhook, you can use any language you like. The following example uses PHP. Here's what it takes to make this code work:

  1. Modify the code below to update the From and To email addresses.
  2. Publish this file to a Twilio-accessible URL on your web server.
  3. Update your Twilio Phone Number's webhook with your application's URL. 
<?php 
/**
* This section ensures that Twilio gets a response.
*/
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<Response></Response>'; //Place the desired response (if any) here
/**
* This section actually sends the email.
*/

/* Your email address */
$to = "your-email@example.com";
$subject = "Message from {$_REQUEST['From']} at {$_REQUEST['To']}";
$message = "You have received a message from {$_REQUEST['From']}. Body: {$_REQUEST['Body']}";
$headers = "From: webmaster@example.com"; // Who should it come from?
mail($to, $subject, $message, $headers);

Any of the parameters which are part of the Twilio Request can also be used.

Have more questions? Submit a request
Powered by Zendesk