title: Angular HTTPClient POST body not sending
body: <p>Currently I am trying to POST a name, email and message from an angular frontend to a php script running in the same nginx server which then runs phpmailer to send an email containing the name, email and message. Here is the code so far:</p>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  import { Email } from './email';
  import {ContactService} from './contact.service';
  import {HttpClient, HttpHeaders} from '@angular/common/http';
  import {NgForm} from '@angular/forms';
  
  const httpOptions = {
    headers: new HttpHeaders({
      'Content-Type':  'application/x-www-form-urlencoded'
    })
  };
  
  const email = new Email('', '', '');
  
  @Component({
    selector: 'app-contact',
    templateUrl: './contact.component.html',
    styleUrls: ['./contact.component.css'],
    providers: [ContactService]
  })
  export class ContactComponent implements OnInit {
  
    email = new Email('', '', '');
  
    constructor(private http: HttpClient) { }
  
    sendEmail(form: NgForm) {
      const value = form.value;
      const senderName = value.name;
      const senderEmail = value.email;
      const senderMessage = value.message;
      this.sendMail(senderName, senderEmail, senderMessage);
    }
  
    sendMail(senderName, senderEmail, senderMessage) {
      console.log(senderName + ' ' + senderEmail + ' ' + senderMessage);
      this.http.post('https://ruffstuffcostumes.tk/assets/scripts/email.php',
        {
          name: senderName,
          email: senderEmail,
          message: senderMessage,
        },
        httpOptions
        )
        .subscribe(
          (val) =&gt; {
            console.log('POST call successful value returned in body',
              val);
          },
          response =&gt; {
            console.log('POST call in error', response);
          },
          () =&gt; {
            console.log('The POST observable is now completed.');
          });
    }
  
    ngOnInit() {
    }
  
  }
  </code></pre>
  
  <p>When I ran the POST request through postman to check it, it ran perfectly well and sent out the email containing the required elements, however when I execute a query with this script, even though the <code>console.log(senderName + ' ' + senderEmail + ' ' + senderMessage)</code> does show the values, it doesn't seem to post them in the body at all, and all I get back is the fact that even though a mail was sent, it was sent without any of those values in the body of the email.</p>
  
  <p>Could it be cross-origin problems (and if so what would be the best way to get around that?), or am I just doing some stupid mistake?</p>