Get Webhook PHP and send by email

I have created a PHP file that receives webhook notifications and writes them to a TXT file but I also want to receive them via email so I added the send email function but it doesn’t work because there is a bug in testing. When I remove the lines “mail(“[email protected]”,”NEW MSG”,”$json”);” it works without errors, so did I do something wrong? Please help.

<?php
$headers = "X-Event-Name: product.update";
$headers = "X-Event-Secret: my_key";
$json = file_get_contents("php://input");
file_put_contents('log.txt', "$json", FILE_APPEND | LOCK_EX);
mail("[email protected]","NEW MSG","$json");
http_response_code(204);