Notification to Discord PHP
If you need to send embed notification use this
I only need a simple notification
$webhookurl = "https://discord.com/api/webhooks/*";
$array = ["will", "this", "show", "an", "array?"];
$json_data = json_encode([
// Message
"content" => json_encode($array),
// Username
"username" => "BOT",
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
$ch = curl_init( $webhookurl );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
// If you need to debug, or find out why you can't send message uncomment line below, and execute script.
// echo $response;
curl_close( $ch );
Use Guzzle
use GuzzleHttp\Client;
$headers = [
'Content-Type' => 'application/json',
];
$client = new Client([
'headers' => $headers
]);
$array = ["this uses guzzle"];
$json_data = [
// Message
"content" => json_encode($array),
// Username
"username" => "BOT",
];
$response = $client->post('https://discord.com/api/webhooks/*', [
'json' => $json_data
]);