PHPackages                             andrew72ru/dkim-lib - 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. [Security](/categories/security)
4. /
5. andrew72ru/dkim-lib

ActiveLibrary[Security](/categories/security)

andrew72ru/dkim-lib
===================

A package to verify the DKIM signature of an email message

v0.0.3(7mo ago)04MITPHPPHP &gt;=8.1

Since Sep 21Pushed 7mo agoCompare

[ Source](https://github.com/andrew72ru/dkim-lib)[ Packagist](https://packagist.org/packages/andrew72ru/dkim-lib)[ RSS](/packages/andrew72ru-dkim-lib/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (0)

DKIM verification library for PHP
=================================

[](#dkim-verification-library-for-php)

A tiny PHP library to verify DKIM signatures of RFC‑2822 email messages using the OpenDKIM C library through PHP FFI.

This package provides a simple wrapper around libopendkim’s verification API, exposing a single entry point (`CheckDKIM`) and a typed enum (`StatusCode`) that mirrors libopendkim’s dkim\_stat return codes.

Features
--------

[](#features)

- Verifies DKIM signatures via `libopendkim` (OpenDKIM)
- Pure PHP API powered by PHP FFI (no PHP extensions besides FFI required)
- Detailed result codes mapped to an enum (`StatusCode`) with human‑readable descriptions
- Optional DNS TXT record check for the DKIM selector before full verification
- Configurable `libopendkim` library path via constructor

Requirements
------------

[](#requirements)

- PHP 8.1+
- PHP FFI enabled (ext-ffi)
- OpenDKIM runtime library available at runtime (shared library, e.g. libopendkim.so or .dylib)

See the `composer.json` for exact PHP and extension constraints.

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

[](#installation)

1. Install via Composer

```
composer require andrew72ru/dkim-lib

```

2. Install the OpenDKIM shared library on your system

- Debian/Ubuntu:
    - `sudo apt-get update && sudo apt-get install -y opendkim libopendkim-dev`
    - The runtime typically installs `libopendkim.so.11` under `/usr/lib` or `/usr/lib/x86_64-linux-gnu`.
- Alpine Linux:
    - `apk add opendkim opendkim-dev`
- CentOS/RHEL (using EPEL):
    - `yum install opendkim opendkim-devel`
- macOS (Homebrew):
    - `brew install opendkim`

If the library is installed in a non‑standard location, you can either:

- pass the full path(s) to the `CheckDKIM` constructor (recommended), or
- adjust your loader path (e.g. `LD_LIBRARY_PATH` on Linux, `DYLD_LIBRARY_PATH` on macOS).

By default, the loader attempts a few common names/paths (e.g. `libopendkim.so.11`). When you pass an array of paths, they will be tried in the given order.

3. Ensure FFI is enabled

FFI must be enabled for CLI and/or FPM where you run verification. In php.ini:

```
; for development you can set
ffi.enable = true
; for production consider preload policies
; ffi.enable = preload

```

Usage
-----

[](#usage)

Below is a minimal example showing how to verify a raw email string and interpret the result:

```
