PHPackages                             simonbackx/slack-php-webhook - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. simonbackx/slack-php-webhook

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

simonbackx/slack-php-webhook
============================

Post messages to your Slack channels with this easy to use library.

1.0.3(7y ago)41837.3k↓22%152MITPHP

Since Mar 15Pushed 7y ago4 watchersCompare

[ Source](https://github.com/SimonBackx/Slack-PHP-Webhook)[ Packagist](https://packagist.org/packages/simonbackx/slack-php-webhook)[ Docs](https://github.com/SimonBackx/Slack-PHP-Webhook)[ RSS](/packages/simonbackx-slack-php-webhook/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (5)Used By (2)

Slack PHP Webhook
=================

[](#slack-php-webhook)

[![Latest Stable Version](https://camo.githubusercontent.com/7e71a994902af04f1d9755233d7eff07eaeaf01e20b6384e95050ae7255e0a81/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e6261636b782f736c61636b2d7068702d776562686f6f6b2f762f737461626c65)](https://packagist.org/packages/simonbackx/slack-php-webhook) [![License](https://camo.githubusercontent.com/16cd92381acfb88e2c73b492166b20c64b50e89451c96723771dbd9a4c47ca6b/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e6261636b782f736c61636b2d7068702d776562686f6f6b2f6c6963656e7365)](https://packagist.org/packages/simonbackx/slack-php-webhook)

Easy to use PHP library to post messages in Slack using incoming webhook integrations.

Setup
=====

[](#setup)

Log in at slack.com with your team. Go to the page with all your integrations. Add a new incoming webhook.

Select a default channel to post your messages. [![Setup1](https://camo.githubusercontent.com/bea87709e05077856792dbe51647bf0760b3467215862926cacd819e927994d9/687474703a2f2f7777772e636c6f6f636b2e62652f75706c6f6164732f736c61636b312e706e67)](https://camo.githubusercontent.com/bea87709e05077856792dbe51647bf0760b3467215862926cacd819e927994d9/687474703a2f2f7777772e636c6f6f636b2e62652f75706c6f6164732f736c61636b312e706e67)

Confirm "Add Incoming WebHook integration" Next, you will find your WebHook URL which you need to use this library. Save it somewhere secure.

[![Setup2](https://camo.githubusercontent.com/b8e0543caa4b2a58a61e74641439472b3f190a5bb176e2465fe94e80c27ad2b1/687474703a2f2f7777772e636c6f6f636b2e62652f75706c6f6164732f736c61636b322e706e67)](https://camo.githubusercontent.com/b8e0543caa4b2a58a61e74641439472b3f190a5bb176e2465fe94e80c27ad2b1/687474703a2f2f7777772e636c6f6f636b2e62652f75706c6f6164732f736c61636b322e706e67)

When you scroll all the way down, you get more options to change your default username, description and icon. You can overwrite these in your code.

Usage
=====

[](#usage)

Installation
------------

[](#installation)

### Composer

[](#composer)

Add Slack-PHP-Webhook to your composer.json file or run `composer require simonbackx/slack-php-webhook`

```
{
  "require": {
    "simonbackx/slack-php-webhook": "~1.0"
  }
}
```

### Alternative

[](#alternative)

Download slack.php and require/include it in your PHP file.

Simple message
--------------

[](#simple-message)

```
// Use the url you got earlier
$slack = new Slack('https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX');

// Create a new message
$message = new SlackMessage($slack);
$message->setText("Hello world!");

// Send it!
if ($message->send()) {
    echo "Hurray 😄";
} else {
    echo "Failed 😢";
}
```

Send to a channel
-----------------

[](#send-to-a-channel)

```
// Use the url you got earlier
$slack = new Slack('https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX');

// Create a new message
$message = new SlackMessage($slack);
$message->setText("Hello world!")->setChannel("#general");

// Send it!
$message->send();
```

Send to a user
--------------

[](#send-to-a-user)

```
// Use the url you got earlier
$slack = new Slack('https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX');

// Create a new message
$message = new SlackMessage($slack);
$message->setText("Hello world!")->setChannel("@simonbackx");

// Send it!
$message->send();
```

Overwriting defaults
--------------------

[](#overwriting-defaults)

You can overwrite the defaults on two levels: in a Slack instance (defaults for all messages using this Slack instance) or SlackMessage instances (only for the current message). These methods will not modify your root defaults at Slack.com, but will overwrite them temporary in your code.

```
$slack = new Slack('https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX');
$slack->setDefaultUsername("SlackPHP robot");
$slack->setDefaultChannel("#general");

// Unfurl links: automatically fetch and create attachments for detected URLs
$slack->setDefaultUnfurlLinks(true);

// Set the default icon for messages to a custom image
$slack->setDefaultIcon("http://www.domain.com/robot.png");

// Use a 👻 emoji as default icon for messages if it is not overwritten in messages
$slack->setDefaultEmoji(":ghost:");

// Create a new message
$message = new SlackMessage($slack);
$message->setText("Hello world!");
$message->setChannel("#general");

// Unfurl links: automatically fetch and create attachments for detected URLs
$message->setUnfurlLinks(false);

// Set the icon for the message to a custom image
$message->setIcon("http://www.domain.com/robot2.png");

// Overwrite the default Emoji (if any) with 😊
$message->setEmoji(":simple_smile:");

// Send it!
$message->send();
```

Attachments
-----------

[](#attachments)

### Create an attachment

[](#create-an-attachment)

Check out  for more details

```
// Use the url you got earlier
$slack = new Slack('https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX');
$slack->setDefaultUsername('Fly company');

// Create a new message
$message = new SlackMessage($slack);

$attachment = new SlackAttachment("Required plain-text summary of the attachment.");
$attachment->setColor("#36a64f");
$attachment->setText("*Optional text* that appears within the attachment");
$attachment->setPretext("Optional text that appears above the attachment block");
$attachment->setAuthor(
    "Author name",
    "http://flickr.com/bobby/", //Optional author link
    "http://flickr.com/bobby/picture.jpg" // Optional author icon
);
$attachment->setTitle("Title", "Optional link e.g. http://www.google.com/");
$attachment->setImage("http://www.domain.com/picture.jpg");

/*
Slack messages may be formatted using a simple markup language similar to Markdown. Supported
formatting includes: ```pre```, `code`, _italic_, *bold*, and even ~strike~.; full details are
available on the Slack help site.

By default bot message text will be formatted, but attachments are not. To enable formatting on
attachment fields, you can use enableMarkdownFor
 */
$attachment->enableMarkdownFor("text");
$attachment->enableMarkdownFor("pretext");
$attachment->enableMarkdownFor("fields");

 // Add fields, last parameter stand for short (smaller field) and is optional
$attachment->addField("Title", "Value");
$attachment->addField("Title2", "Value2", true);
$attachment->addField("Title", "Value", false);

// Add a footer
$attachment->setFooterText('By Simon');
$attachment->setFooterIcon('https://www.simonbackx.com/favicon.png');
$attachment->setTimestamp(time());

// Add it to your message
$message->addAttachment($attachment);

// Send
$message->send();
```

[View the result](https://api.slack.com/docs/messages/builder?msg=%7B%0A%20%20%20%20%22text%22%3A%20%22%22%2C%0A%20%20%20%20%22username%22%3A%20%22Fly%20company%22%2C%0A%20%20%20%20%22attachments%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22fallback%22%3A%20%22Required%20plain-text%20summary%20of%20the%20attachment.%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22color%22%3A%20%22%2336a64f%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22pretext%22%3A%20%22Optional%20text%20that%20appears%20above%20the%20attachment%20block%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22author_name%22%3A%20%22Author%20name%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22mrkdwn_in%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22text%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pretext%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22fields%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22author_link%22%3A%20%22http%3A%2F%2Fflickr.com%2Fbobby%2F%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22author_icon%22%3A%20%22http%3A%2F%2Fflickr.com%2Fbobby%2Fpicture.jpg%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Title%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title_link%22%3A%20%22Optional%20link%20e.g.%20http%3A%2F%2Fwww.google.com%2F%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22text%22%3A%20%22%2AOptional%20text%2A%20that%20appears%20within%20the%20attachment%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22fields%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Title%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%20%22Value%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Title2%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%20%22Value2%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22short%22%3A%20true%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Title%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%20%22Value%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22short%22%3A%20false%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22image_url%22%3A%20%22http%3A%2F%2Fwww.domain.com%2Fpicture.jpg%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22footer%22%3A%20%22By%20Simon%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22footer_icon%22%3A%20%22https%3A%2F%2Fwww.simonbackx.com%2Ffavicon.png%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22ts%22%3A%201523486931%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%5D%0A%7D)

Add buttons
-----------

[](#add-buttons)

```
// Use the url you got earlier
$slack = new Slack('https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX');
$slack->setDefaultUsername('Fly company');

// Create a new message
$message = new SlackMessage($slack);
$message->setText(" approved your travel request. Book any airline you like by continuing below.");

// Create a new Attachment with fallback text, a plain-text summary of the attachment.
// This text will be used in clients that don't show formatted text (eg. IRC, mobile
// notifications) and should not contain any markup.
$attachment = new \SlackAttachment('Book your flights at https://flights.example.com/book/r123456');
$attachment->addButton('Book flights 🛫', 'https://flights.example.com/book/r123456');
$attachment->addButton('Unsubscribe', 'https://flights.example.com/unsubscribe', 'danger');

$message->addAttachment($attachment);

$message->send();
```

[View the result](https://api.slack.com/docs/messages/builder?msg=%7B%0A%20%20%20%20%22text%22%3A%20%22%3C%40W1A2BC3DD%3E%20approved%20your%20travel%20request.%20Book%20any%20airline%20you%20like%20by%20continuing%20below.%22%2C%0A%20%20%20%20%22username%22%3A%20%22Fly%20company%22%2C%0A%20%20%20%20%22icon_emoji%22%3A%20%22%3Aairplane%3A%22%2C%0A%20%20%20%20%22attachments%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22fallback%22%3A%20%22Book%20your%20flights%20at%20https%3A%2F%2Fflights.example.com%2Fbook%2Fr123456%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22actions%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22button%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22text%22%3A%20%22Book%20flights%20%F0%9F%9B%AB%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22url%22%3A%20%22https%3A%2F%2Fflights.example.com%2Fbook%2Fr123456%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22button%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22text%22%3A%20%22Unsubscribe%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22url%22%3A%20%22https%3A%2F%2Fflights.example.com%2Funsubscribe%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22style%22%3A%20%22danger%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%5D%0A%7D)

### Add (multiple) attachments

[](#add-multiple-attachments)

```
$message = new SlackMessage($slack);
$message->addAttachment($attachment1);
$message->addAttachment($attachment2);
$message->send();
```

Short syntax
------------

[](#short-syntax)

All methods support a short syntax. E.g.:

```
(new SlackMessage($slack))
    ->addAttachment($attachment1)
    ->addAttachment($attachment2)
    ->send();
```

Warning
=======

[](#warning)

Each message initiates a new HTTPS request, which takes some time. Don't send too much messages at once if you are not running your script in a background task.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity50

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 90.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~29 days

Total

4

Last Release

2898d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1ed7b1a63cb3850cd32304fab42cf597ca25b8d81a7e86666b5e4673e606ab3e?d=identicon)[SimonBackx](/maintainers/SimonBackx)

---

Top Contributors

[![SimonBackx](https://avatars.githubusercontent.com/u/5277847?v=4)](https://github.com/SimonBackx "SimonBackx (39 commits)")[![mikesprague](https://avatars.githubusercontent.com/u/560705?v=4)](https://github.com/mikesprague "mikesprague (4 commits)")

---

Tags

messageloggingslackwebhookchannels

### Embed Badge

![Health badge](/badges/simonbackx-slack-php-webhook/health.svg)

```
[![Health](https://phpackages.com/badges/simonbackx-slack-php-webhook/health.svg)](https://phpackages.com/packages/simonbackx-slack-php-webhook)
```

###  Alternatives

[saasscaleup/laravel-log-alarm

Laravel log Alarm help you to set up alarm when errors occur in your system and send you a notification via Slack and email

27025.0k](/packages/saasscaleup-laravel-log-alarm)[andrey-tech/bitrix24-api-php

Обертка на PHP7+ для работы с API Битрикс24 с использованием механизма входящих вебхуков, троттлингом запросов и логированием в файл

9874.2k](/packages/andrey-tech-bitrix24-api-php)[lefuturiste/monolog-discord-handler

A simple monolog handler for support Discord webhooks

34111.6k4](/packages/lefuturiste-monolog-discord-handler)[thecoder/laravel-monolog-telegram

Telegram Handler for Monolog

2939.5k](/packages/thecoder-laravel-monolog-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
