Extension of the wonderful SPF-LIB library by mlocati (https://github.com/mlocati/spf-lib)
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 (https://github.com/mlocati/spf-lib) can do
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 (https://github.com/mlocati/spf-lib), you can use this PHP library to build, validate, flatten, split, and check the SPF records.
You can install this library with Composer:
composer require midweste/spf-lib-flattener
namespace SpfLibFlattener;
require __DIR__ . '/../vendor/autoload.php';
$domain = 'example.com';
$spf = new SpfFlattener($domain);
$flatArray = $spf->toFlatArray();
$flatString = $spf->toFlatString();
$flatRecord = $spf->toFlatRecord();
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();
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<br/>" . PHP_EOL;
}
You can offer the original author that did all the heavy lifting (mlocati) a monthly coffee or a one-time coffee 😉