html code
<form>
<div class="list">
<div class="list list-inset" >
<label class="item item-input" id="descriptions">
<input type="text" height:"90" class="description" placeholder="Description ..." ng-model="data.describe" required>
</label>
<label input="email" class="item item-input" id="email" ng-model="data.email" required >
<span class="input-label">Email</span>
<input type="email">
</label>
<label class="item item-input">
<span class="input-label">Date</span>
<input type="date">
</label>
</div>
<button class="button button-block button-balanced" type="submit" ng-click="AddItem(); submitForm()">
Add Item
</button>
<button class="button button-block button-assertive" ng-click="closeModal()"> cancel</button>
</div>
</form>
app.js
$scope.data = {
description: "default",
email: "default",
date: "default",
};
$scope.submitForm = function() {
console.log("posting data....");
$http.post('http://localhost:4400/api.php', JSON.stringify($scope.data)).success(function () {/*success callback*/ });
};
api.php
<?php
$name=$_POST['descriptions'];
$email=$_POST['email'];
$message=$_POST['date'];
if (($descriptions =="")||($email=="")||($date==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";
}
else{
$from="From: $descriptions<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form" + $date;
mail("testing@gmail.com", $subject, $message, $from);
echo "Email sent!";
}
?>
我正在尝试将表单的内容发送到提供的电子邮件地址。问题是当我尝试这样做时,我收到一个错误:POST http://localhost:4400/api.php 404(Not Found)。我查看了其他帖子,无法解决此问题,谢谢。
在此输入图片说明
答案 0 :(得分:0)
在您的代码中使用http://localhost:4400/api.php
代替api.php
并改变像这样的提交
<form action="api.php" method="post" id="myform" name="myform">
和
<button onclick="document.getElementById("myform").submit()">SUBMIT</button>
答案 1 :(得分:0)
您可以将您的php文件与相对网址相关联。如果您的文件api.php
位于app/
,则可以在app.js
中写下:
$scope.submitForm = function() {
$http.post('api.php', JSON.stringify($scope.data), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
};
在api.php
:
$descriptions = $_POST['descriptions'];
$email = $_POST['email'];
$date = $_POST['date'];