javascript - Trying to post data from an angular html page to a php page for processing and email -


i've been working angular short time , i'm trying contact form submit php file @ domain route that's set mail us.

i've gotten php mail none of date being carried on angular application.

here's code:

angular.module('demoapp')    .controller('contactctrl', function ($scope, $http, $templatecache) {      var method = 'post';    var url = 'contact.php';    $scope.codestatus = '';    $scope.add = function() {      $http({        method: method,        url: url,        data: $.param({'data' : formdata}),        headers: {'content-type': 'application/x-www-form-urlencoded'},        cache: $templatecache      }).      success(function(response) {          $scope.codestatus = response.data;      }).      error(function(response) {          $scope.codestatus = response || 'request failed';      });      return false;    };      });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>    <div class="contact-form-wrapper">    <h2>write us</h2>    <form action="contact.php" method="post" enctype="text/plain">      <input class="formtop" type="text" name="name" placeholder="name (required)">      <input class="formtop" type="text" name="mail" placeholder="email (required)">      <input class="formlong" type="text" name="subject" placeholder="subject" size="50">      <textarea class="formarea" name="message" placeholder="message" size="50"></textarea>      <input class="submit-link" type="submit" value="send">    </form>  </div>

it's posting php file:

<?php  $subject = $_post['subject']; $name = $_post['name']; $email = $_post['mail']; $message = $_post['message'];  date_default_timezone_set('america/los_angeles'); $ip_address = $_server['remote_addr']; $hostname = gethostbyaddr($_server['remote_addr']); $date = date ("l, f js, y"); $time = date ("h:i a"); $to = "dummy@email.com"; $subject = $subject; $msg=" name: $name email: $email subject: $subject message: $message submitted on: $date $time ip address: $ip_address host name: $hostname \n ";  mail($to, $subject, $msg, "from: website@traffikonline.com"); ?> 

it's minor i'm missing, i've checked lot of places answers , closest i've gotten. grunt , inspector isn't tossing errors jscript , php file email me (just no data).

thanks!

update php :

$data = file_get_contents('php://input'); $json = json_decode($data); $subject = $json->subject; $name = $json->name; $email = $json->mail; $message = $json->message; 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -