Skip to content
Advertisement

Angular – PHP -> send mail null php values

I need help in my code, I’m trying to send a FormData from Angular to PHP and later send a mail, always appears the PHP vars empty, I’m doing something wrong and doesn’t see what

On the HTML use formGroup and ngSubmit

My HTML code:

JavaScript

On the Ts use the FormControl Validators and the http.post to pass the data to PHP

My .ts code:

JavaScript

On tje PHP retrieve the JSON from Angular with this

$postdata = file_get_contents(“php://input”); $request = json_decode($postdata);

My PHP code:

JavaScript

Advertisement

Answer

You don’t need FormData to send JSON to your API. Even if you force the content type to application/json, I’m not sure it will be properly formatted.

Plain JavaScript objects can be sent as JSON using the angular HTTP client. To do so, pass a plain object to the post method:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement