title: I am trying to send an email via angular. Am I approaching this in the correct manner?
body: <p>I'm just trying to learn something new.  I want to be able to send an email using angular and php.  I am turning my form data into an object. Then I want to send this object as a variable and send the data to a php file. I am able to create the variable but I don't believe the data is being set in the php file. What am I missing here?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>angular.module('app', []);
  var vm = this;
  
  var url = '/contact-form-handler.php';
  vm.codeStatus = "";
  vm.form = {};
  
  vm.submit = function($event) {
  
    $event.preventDefault();
  
    console.log(this.form);
    $http({
      method: "POST",
      url: url,
      data: vm.form,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    }).
    success(function(result) {
      console.log(result);
      console.log('hit');
    }).
    error(function(result) {
      console.log('error');
    });
    return false;
  
  };</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"&gt;&lt;/script&gt;
  
  &lt;?php
  
  header('Access-Control-Allow-Origin: *');
  
  
  if (isset($_POST["data"])) {
  
   $from = 'Portfolio';
   $to = 'rafael.heard@gmail.com';
      $subject = 'Portfolio Inquiry';
   $body = $_POST['data'];
  
  
   mail($to, $subject, $body, $from);
  
      $result = 'mail sent';
   
  }else{
   $result =  'not set';
  }
  ?&gt;
  
  &lt;div ng-app="app" ng-controller="MainController as main"&gt;
    &lt;form role="form" name="contactForm" ng-submit="main.submit($event)" required novalidate&gt;
      &lt;div class="form-groups"&gt;
        &lt;div class="group"&gt;
          &lt;input type="text" name="username" ng-model="main.form.name" placeholder="Name (required)" required /&gt;
        &lt;/div&gt;
  
        &lt;div class="group"&gt;
          &lt;input type="email" name="userEmail" ng-model="main.form.email" placeholder="Email (required)" required /&gt;
        &lt;/div&gt;
  
        &lt;div class="group"&gt;
          &lt;textarea type="text" name="message" ng-model="main.form.message" ng-minlength="10" rows="10" required&gt;&lt;/textarea&gt;
        &lt;/div&gt;
  
        &lt;button&gt;Send&lt;/button&gt;
      &lt;/div&gt;
    &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>