0

Preface by saying I'm totally new to this.

I "created" a basic account on amazon S3 to stand up a static website so that I could create the webhook. The basic idea is to take SMS sent to a phone number and forward those messages to an email address.

The code given to me by Twilio for the webhook is the following:

<?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); 

I added my email address between the quotes in the $to and $headers - "from lines. I then saved this file, which I made in text edit, into a .php and uploaded it to the S3 website. I made sure it was public.

I placed the automatically generated URL into the twilio "a message comes in" webhook field.

But it doesn't work. Any idea why? Is an S3 static website not the appropriate place for this, or am I uploading the file wrong?

  • Forward SMS messages to an email account using Twilio Functions and Mailgun API, check my answer to this SO question: https://stackoverflow.com/questions/44768719/can-i-forward-sms-to-an-email-using-only-a-twiml-bin – Alex Baban Jun 29 '17 at 05:56
  • 2
    Static web site hosting in S3 does not support [*"server-side processing, including server-side scripts such as PHP, JSP, or ASP.NET."*](http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html) – Michael - sqlbot Jun 29 '17 at 09:33

1 Answers1

1

Can you access the URL from a web browser, or an http utility like curl? First step would be to insure your site works outside Twilio and returns the XML you expect.

Also, does your web page accept the HTTP verb that Twilio is configured to use (POST by default).

Tony Bruni
  • 101
  • 1
  • I see that the problem may be that amazon s3 doesn't support server-side functions. I'm literally just creating this webpage for the purpose of sending texts to email. My plan is to purchase a domain name and find a cheap host for it. From your comment re: HTTP I assume that something needs to be configured to accept Twilio's http verbage. I'm going to to have to look into that (again, clearly NOT a web developer by trade ;) ). Thanks for your answer! – Carol B. Jul 03 '17 at 20:44