I get POST 405 (Not Allowed) in the console whenever I try to send a message through a contact form.
App.js
$scope.submitData = function() {
$http({
url: 'handle.php',
method: 'POST',
data: {"name": $scope.name,"email": $scope.email,"message": $scope.message},
headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
})
.success(function() {
window.alert("Success");
})
.error(function() {
window.alert("Failure");
})
}
Handle.php
$json = file_get_contents("php://input");
$data = json_decode($json, true);
$to = "myemail@gmail.com";
$name = $data['name'];
$email = $data['email'];
$message = $data['message'];
//to, subject, message, headers, parameters.
mail($to, $name, $email, $message);
?>
Contact.html
<form action="" method="post" ng-submit="submitData()" ng-controller="contactController">
<p>name:</p>
<input name="name" type="text" ng-model="name">
<p>email:</p>
<input name="email" type="text" ng-model="email">
<p>message:</p>
<textarea name="message" type="text" cols="40" rows="5" ng-model="message"></textarea>
<p><div id="html_element"></div><p>
<input type="submit" id="submit" value="Submit"/>
</form>
I'm running a nginx web server on raspberry pi.
Is the handle.php correct?
I assume that this error means that something is not configured on the server? What do I need to configure?
I would appreciate any help.
I think you should install a plugin to make ajax call to other servers. Try download this and may it help: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
After install, click the plugin, add and url: https://developer.chrome.com/extensions/match_patterns and then try again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.