邮递http://localhost:4400/api.php 404(未找到)angularjs html代码 电子邮件 日期 添加项 取消 app.js $scope.data={ description:“默认”, 电子邮件:“默认”, 日期:“默认”, }; $scope.submitForm=function(){ console.log(“发布数据…”); $http.post('http://localhost:4400/api.php,JSON.stringify($scope.data)).success(函数(){/*successcallback*/}); }; api.php

邮递http://localhost:4400/api.php 404(未找到)angularjs html代码 电子邮件 日期 添加项 取消 app.js $scope.data={ description:“默认”, 电子邮件:“默认”, 日期:“默认”, }; $scope.submitForm=function(){ console.log(“发布数据…”); $http.post('http://localhost:4400/api.php,JSON.stringify($scope.data)).success(函数(){/*successcallback*/}); }; api.php,php,angularjs,forms,email,Php,Angularjs,Forms,Email,我正在尝试将表单内容发送到提供的电子邮件地址。问题是当我尝试这样做时,我得到了一个错误:POST 404(未找到)。我看了其他帖子,无法解决这个问题,谢谢 在此处输入图像描述使用http://localhost:4400/api.php而不是在您的代码中使用api.php 然后像这样提交 html code <form> <div class="list"> <div class="list

我正在尝试将表单内容发送到提供的电子邮件地址。问题是当我尝试这样做时,我得到了一个错误:POST 404(未找到)。我看了其他帖子,无法解决这个问题,谢谢


在此处输入图像描述

使用
http://localhost:4400/api.php
而不是在您的代码中使用
api.php
然后像这样提交

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!"; 
        } 

?>

提交

您可以使用相对url链接php文件。如果您的文件
api.php
位于
app/
中,您可以在
app.js
中编写:

<button onclick="document.getElementById("myform").submit()">SUBMIT</button>
api.php
中:

$scope.submitForm = function() {
   $http.post('api.php', JSON.stringify($scope.data), {
       headers: {
         'Content-Type': 'application/x-www-form-urlencoded'
       }
   });
};

为什么要将PHP与angular结合起来?使用nodejs替代此项目的需求。您是否能够运行
http://localhost:4400
?api.php在同一根文件夹中?@user3303871啊,好的,我可以运行,api.php与index.htmlhank您Berlik Tradingplc在同一个位置,仍然不幸运您可以检查应用程序live您的托管服务器可能不允许使用php邮件功能。大多数主机都是这样的。你能告诉我你项目的树结构吗?任务菜单->www->api.phpHum ok^。根据本文,您必须将php文件放在
www
文件夹之外。您在什么环境下编写应用程序?你用的是MAMP还是WAMP?如果没有,您需要将php文件放在服务器上,然后将新路径链接到post请求。wamp是im使用的服务器吗
$scope.submitForm = function() {
   $http.post('api.php', JSON.stringify($scope.data), {
       headers: {
         'Content-Type': 'application/x-www-form-urlencoded'
       }
   });
};
   $descriptions = $_POST['descriptions']; 
   $email = $_POST['email']; 
   $date = $_POST['date'];