I am trying to create a Webhook in PHP that receives information in JSON
This is the information that is sent to the Webhook:
{
"email": "email@example.com",
"id": "a49608778we9xca4960a8h11gqd1vsq",
"name": "Test"
}
This is my PHP code
$json = file_get_contents('php://input');
$action = json_decode($json, true);
$email = $action->email;
$id = $action->id;
$name = $action->name;
if($json = json_decode(file_get_contents("php://input"), true)) {
print_r($json);
$data = $json;
} else {
print_r($_POST);
$data = $_POST;
}
The problem is that the JSON information that is sent through the webhooks cannot be stored in the variables.
My objective is to send an email with the data received through the webhook
$to = $email;
$title = "{$name}! Your Diagnosis is ready";
// message
$message = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xmlns:o='urn:schemas-microsoft-com:office:office' style='font-family:roboto, 'helvetica neue', helvetica, arial, sans-serif'>
<head>
<meta charset='UTF-8'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta name='x-apple-disable-message-reformatting'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta content='telephone=no' name='format-detection'>
<title>Hello {$name}!</title><!--[if (mso 16)]>
</head>
<body>
Hello {$name}
</body>
</html>";
// To send an HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= "To: $name <$email>" . "\r\n";
$headers .= 'From: Test <test@test.co>' . "\r\n";
// Send it
mail($to, $title, $message, $headers);
Sun however I have not been able to get it to work, since I do not receive any mail