PHP

Discord Webhook Notification

admin by @admin ADMIN
Jun 20, 2026
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
Same idea as Slack but for Discord webhooks — supports rich embeds with a title, description, and color. Useful for dev/ops dashboards or bot integrations.
PHP
Raw
<?php
function discordNotify(string $webhookUrl, string $title, string $description, int $color = 0x36a64f): bool {
    $payload = ['embeds' => [[
        'title'       => $title,
        'description' => $description,
        'color'       => $color,                 // decimal int, e.g. 0xFF0000 for red
        'timestamp'   => date('c'),
    ]]];

    $ch = curl_init($webhookUrl);
    curl_setopt_array($ch, [
        CURLOPT_POST           => true,
        CURLOPT_POSTFIELDS     => json_encode($payload),
        CURLOPT_HTTPHEADER     => ['Content-Type: application/json'],
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT        => 5,
    ]);
    curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
    curl_close($ch);
    return $code === 204;     // Discord returns 204 on success
}

discordNotify('https://discord.com/api/webhooks/...', 'Deploy succeeded', 'v2.3.1 is live', 0x10B981);
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.