I recently created a contact form for my Angular 7 website, which sends a JSON object to a PHP file.
Here is a screenshot of the console error message
Although the POST request is working, I am receiving a 404 error. The MessageService is passing the absolute path to the PHP file along with the message object. Here is a snippet from the message.service.ts file:
export class MessageService {
baseUrl = '<domain>/dev/src/app/entities/contact/message.php';
constructor(private http: HttpClient) { }
send(message: Message) {
this.http.post(this.baseUrl, { data: message }).subscribe((data) => {
console.log('Sent Data', data);
}, (error) => {
console.log('Something went wrong', error);
});
}
}
Here is the content of the message.php file:
<?php
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
$post = file_get_contents('php://input');
echo $postdata;
?>
Both the MessageService and message.php are located in the same folder. However, I am uncertain if the absolute path specified in the POST request is correct.
You can view the file tree by clicking here
I would greatly appreciate any assistance in resolving this issue.
Thank you in advance
Sascha