-2

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

esqew
  • 42,425
  • 27
  • 92
  • 132
  • Does this answer your question? [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – Tangentially Perpendicular Apr 03 '22 at 00:08
  • @TangentiallyPerpendicular Unfortunately not, since what happens is that my code is not correctly capturing the variables that are sent through the webhook and, therefore, it is not sending the email – Santiago Bastidas Apr 03 '22 at 00:15
  • 1
    Well, then, you need to say that in your question. Posting a load of code without explaining exactly where your problem is won't get you an answer. – Tangentially Perpendicular Apr 03 '22 at 00:44

1 Answers1

0

Try assigning the values using this notation instead.

$email = $action["email"];
$id = $action["id"];
$name = $action["name"];
JoseStack
  • 167
  • 2
  • 12