-1

I am new to aws and php. I am running into a problem trying to setup a basic send form on a static amazon s3 site.

Error 405 Method Not Allowed Code: MethodNotAllowed Message: The specified method is not allowed against this resource. Method: POST ResourceType: OBJECT RequestId: B41697D6C61AFFCE HostId: imaELAWJKISLaPfU1tAbhFaIPAgoRxoUsU7JMcc/x9MSS5SOrU6LiW8sVuS4jTw+d2SdWdbjHQ4=

PHP

   <?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "support@website.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>

HTML

            <form method="post" action="#">
                                        <div class="fields">
                                            <div class="field half">
                                                <label for="name">Name</label>
                                                <input type="text" name="name" id="name" />
                                            </div>
                                            <div class="field half">
                                                <label for="email">Email</label>
                                                <input type="text" name="email" id="email" />
                                            </div>
                                            <div class="field">
                                                <label for="message">Message</label>
                                                <textarea name="message" id="message" rows="5"></textarea>
                                            </div>
                                        </div>
                                        <ul class="actions">
                                            <li><a href="" class="button submit">Send Message</a></li>
                                        </ul>
                                    </form>


Can you point me in the right direction?
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • 1
    You need to allow POST to the specified URL, like so: https://stackoverflow.com/questions/36404379/how-to-configure-aws-s3-to-allow-post-to-work-like-get – Zachary Craig Oct 17 '18 at 16:35

1 Answers1

2

PHP is not static. You can only serve static resources from S3. You can't run PHP code on S3.

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • That was the answer I was afraid of. Is there another solution or do you suggest taking the form down? – Daniel Maher Oct 17 '18 at 15:49
  • Clientside javascript which makes the POST request? – Sean Pianka Oct 17 '18 at 16:50
  • 1
    @DanielMaher If you want to host back-end dynamic code you need to look into EC2/ECS/EKS/Elastic Beanstalk, or a really cheap option would be to use AWS Lambda. – Mark B Oct 17 '18 at 17:34
  • I know links are not recommended for documentation but I believe this to be the solution I am looking for https://aws.amazon.com/blogs/architecture/create-dynamic-contact-forms-for-s3-static-websites-using-aws-lambda-amazon-api-gateway-and-amazon-ses/ – Daniel Maher Oct 17 '18 at 18:42