I am trying to run a contact form using Angular 8. I have found a solution here, but after adapting the code to mine, the console gives me an error 500. I'm a bit stuck here. What do I still have to do? what is wrong? thanks for advance.
This is my last version code: https://github.com/BiggsBottor/Portfolio.git
but these two files are that I'm trying to run:
contact.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Contact } from '../models/contact';
@Injectable({
  providedIn: 'root'
})
export class ContactService {
  baseUrl = 'http://localhost/portfolio/api';
  // baseUrl = '../../../api';
  contact: Contact;
  constructor(private http: HttpClient) { }
  sendEmail() {
    console.log(this.contact);
    this.http.post(`${this.baseUrl}/email.php`, this.contact)
                  .subscribe(resp => console.log(resp), resp => console.log(resp));
  }
}
email.php
<?php 
switch($_SERVER['REQUEST_METHOD']){
case("OPTIONS"): //Allow preflighting to take place.
    header("Access-Control-Allow-Origin: *");
    header("Access-Control-Allow-Methods: POST");
    header("Access-Control-Allow-Headers: content-type");
    exit;
case("POST"): //Send the email;
    header("Access-Control-Allow-Origin: *");
    $json = file_get_contents('php://input');
    $params = json_decode($json);
    $name = $params->name;
    $email = $params->email;
    $phone = $params->phone;
    $subject = $params->subject;
    $message = $params->message;
    // the structure of the email itself
    $to = 'my-personal-email@gmail.com';
    $subject = "Portfolio Contact Form with topic: $subject";
    $body = "From:\n\nName: $name";
    $body .= "Email: $email\n\n";
    $body .= "Phone: $phone\n\n";
    $body .= "Message:\n$message";
    $header = "From: $name <$email>";
    if (!mail($to, $subject, $body, $header)) { 
        http_response_code(500); 
    }
    break;
default: //Reject any non POST or OPTIONS requests.
    header("Allow: POST", true, 405);
    exit;
}
?>
