I have a simple php email form where the form is validated and submitted through an ajax call to an email.php. It works fine on my own server, but on Amazon S3 I get the error: MethodNotAllowedThe specified method is not allowed against this resource.OBJECTPOST2871412DE... and then a continuing string of numbers and letters.
my php file is as follows
<?php
$to = "person@domain.com";
$subject = "Message from ".$_POST['my_name'];
$person = $_POST['my_name'];
$email = $_POST['my_email'];
$comments = $_POST['my_comments'];
$headers = "From: ".$email."\r\n" .
"Reply-To: ".$email. "\r\n";
$message = "Entry from: ".$person." (".$email.")\n\n Comments: ".$comments;
$result = mail($to, $subject, $message, $headers);
?>
Here is the ajax call (w the absolute php url censored):
$(document).ready(function(){
$("#emailSubmitBtn").click(function(){
if ( $("#contactForm").valid() ) {
var myName = $('#my_name').val();
var myEmail = $('#my_email').val();
var myComments = $('#my_comments').val();
var dataString = 'my_name='+ myName + '&my_email=' + myEmail + '&my_comments=' + myComments;
$.ajax({
type: "POST",
url: "http://####.s3.amazonaws.com/email.php",
data: dataString,
success: function() {
$('#contact').html("<div id='message'></div>");
$('#message').html("<p>Thank you for submitting the form!</p>")
.hide()
.fadeIn(1500);
}
});
return false;
}
});
});
Amazon S3 can’t execute PHP files, so what you’re trying to do simply won’t work.
You can post a file to an S3 bucket (rather than a specific file URL, hence the allowed method error), but you can’t run code there. It’s the Simple Storage Service.