PHPackages                             midweste/spf-lib-flattener - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. midweste/spf-lib-flattener

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

midweste/spf-lib-flattener
==========================

A library to flatten SPF records

114PHP

Since Apr 24Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

SPF (Sender Policy Framework) Flattening/Splitting Library
==========================================================

[](#spf-sender-policy-framework-flatteningsplitting-library)

No tests yet - Use at your own risk!
====================================

[](#no-tests-yet---use-at-your-own-risk)

Extension of the wonderful SPF-LIB library by mlocati ()

This PHP library allows you to:

- flatten a spf record into ips addresses
- split a flattened spf record into primary and child spf records
- get the SPF record from a domain name (parent lib mlocati/spf-lib)
- decode and validate the SPF record (parent lib mlocati/spf-lib)
- create the value of a TXT record (parent lib mlocati/spf-lib)
- check if domains and IP addresses satisfy the SPF records (parent lib mlocati/spf-lib)
- all the rest of what SPF-LIB library by mlocati () can do

Short introduction about SPF Flattener/Splitter
-----------------------------------------------

[](#short-introduction-about-spf-flattenersplitter)

This library is meant to address the issue where more than 10 lookups are present in a SPF record.

There are two parts:

- RecordFlattener - this class will flatten an spf record into an aggregated list of ips addresses
- RecordSplitter - takes a flattened record and split the ip addresses of into child records like spf1.domain.com spf2.domain.com

Because this is an extension to the wonderful SPF-LIB library by mlocati (), you can use this PHP library to build, validate, flatten, split, and check the SPF records.

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

[](#installation)

You can install this library with Composer:

```
composer require midweste/spf-lib-flattener
```

Usage
-----

[](#usage)

### Flattening an spf record from a domain name

[](#flattening-an-spf-record-from-a-domain-name)

```
namespace SpfLibFlattener;

require __DIR__ . '/../vendor/autoload.php';

$domain = 'example.com';
$spf = new SpfFlattener($domain);

$flatArray = $spf->toFlatArray();
$flatString = $spf->toFlatString();
$flatRecord = $spf->toFlatRecord();
```

### Flattening an spf record from an existing string record

[](#flattening-an-spf-record-from-an-existing-string-record)

```
namespace SpfLibFlattener;

require __DIR__ . '/../vendor/autoload.php';

$domain = 'example.com';

// Flatten a record by passing the record as a string
$record = 'v=spf1 include:example.com include:google.com -all';
$spf = SpfFlattener::createFromText($domain, $record);
$flatArray = $spf->toFlatArray();
$flatString = $spf->toFlatString();
$flatRecord = $spf->toFlatRecord();
```

### Splitting an spf record from an existing string record

[](#splitting-an-spf-record-from-an-existing-string-record)

```
namespace SpfLibFlattener;

require __DIR__ . '/../vendor/autoload.php';

$domain = 'example.com';
$spf = new SpfFlattener($domain);

$splitter = RecordSplitter::createFromTxt($spf->toFlatString());
$split = $splitter->split(512, 'spf#.' . $domain);

foreach ($split as $name => $r) {
    echo "name:$name record:$r" . PHP_EOL;
}
```

Do you want to really say thank you?
------------------------------------

[](#do-you-want-to-really-say-thank-you)

You can offer the original author that did all the heavy lifting (mlocati) a [monthly coffee](https://github.com/sponsors/mlocati) or a [one-time coffee](https://paypal.me/mlocati) 😉

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2df4ed3abb19aaf4771d0bc1b64769b21ae06929b32165560884f545fb80d0af?d=identicon)[midwestE](/maintainers/midwestE)

### Embed Badge

![Health badge](/badges/midweste-spf-lib-flattener/health.svg)

```
[![Health](https://phpackages.com/badges/midweste-spf-lib-flattener/health.svg)](https://phpackages.com/packages/midweste-spf-lib-flattener)
```

###  Alternatives

[michael-rubel/laravel-couponables

This package provides polymorphic coupon functionality for your Laravel application.

19590.7k1](/packages/michael-rubel-laravel-couponables)[loadsys/cakephp_sitemap

A CakePHP Plugin for adding automatic XML and HTML Sitemaps to an app

2819.6k](/packages/loadsys-cakephp-sitemap)[mauricerenck/komments

A comment and webmention plugin for Kirby 3

501.2k1](/packages/mauricerenck-komments)[myweb/show-out-of-stock-products

Show out-of-stock product configurations for configurable products on the front end.

131.7k](/packages/myweb-show-out-of-stock-products)

PHPackages © 2026

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