Download the PHP package cbowofrivia/dmarc-record-builder without Composer
On this page you can find all versions of the php package cbowofrivia/dmarc-record-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cbowofrivia/dmarc-record-builder
More information about cbowofrivia/dmarc-record-builder
Files in cbowofrivia/dmarc-record-builder
Package dmarc-record-builder
Short Description A lean package that makes creating DMARC records user friendly
License MIT
Homepage https://github.com/cbowofrivia/dmarc-record-builder
Informations about the package dmarc-record-builder
DMARC Record Builder
A PHP package for building and parsing DMARC DNS records with a fluent, human-friendly API. Accepts readable values ('relaxed', 'strict', 'reject') and outputs correctly formatted DMARC strings.
Requirements
- PHP 8.3 or higher
This package has no runtime dependencies.
Installation
Quick Start
Building a Record
Fluent API
All setter methods return $this, so calls can be chained:
Constructor
All parameters are optional. The constructor accepts the same values as the fluent setters:
Static Factory
DmarcRecord::create() is a convenience wrapper around the constructor, useful when you want to build and cast in one expression:
Parsing an Existing Record
Pass a raw DMARC TXT record string to DmarcRecord::parse() to get a populated DmarcRecord object. This is useful for reading and modifying existing records.
After parsing, you can modify the record and re-cast it to a string:
parse() requires both v and p tags to be present and will throw an InvalidDmarcRecordException if either is missing. Unknown tags are silently ignored.
Tag Reference
| Method | DMARC Tag | Accepted Values | Default |
|---|---|---|---|
version() |
v |
'DMARC1' |
'DMARC1' |
policy() |
p |
'none', 'quarantine', 'reject' |
'none' |
subdomainPolicy() |
sp |
'none', 'quarantine', 'reject' |
null |
rua() |
rua |
'mailto:...' |
null |
ruf() |
ruf |
'mailto:...' |
null |
adkim() |
adkim |
'relaxed', 'strict' |
null |
aspf() |
aspf |
'relaxed', 'strict' |
null |
reporting() |
fo |
'all', 'any', 'dkim', 'spf' |
[] |
nonExistentSubdomainPolicy() |
np |
'none', 'quarantine', 'reject' |
null |
publicSuffixDomainPolicy() |
psd |
'y', 'n', 'u' |
null |
testingMode() |
t |
'y', 'n' |
null |
Tags with a null value are omitted from the output string. Only v and p are always emitted.
Note: RFC 9989 (DMARCbis) removed the
pctandritags, so this package no longer supports them (removed in4.0.0). Records that still contain those tags parse without error — the tags are simply ignored.
Tag Details
policy() / subdomainPolicy() / nonExistentSubdomainPolicy()
Controls how the receiving mail server handles messages that fail DMARC checks.
'none'— take no action; useful during monitoring'quarantine'— send to spam/junk'reject'— reject the message outright
subdomainPolicy() (sp) overrides policy() for subdomains. If omitted, subdomains inherit the main policy.
nonExistentSubdomainPolicy() (np) applies to non-existent subdomains (RFC 9091 / DMARCbis). Takes precedence over both policy() and subdomainPolicy() for those domains.
rua() / ruf()
URIs for receiving DMARC reports. Must be prefixed with mailto:.
rua— aggregate reports (daily summaries from receivers)ruf— forensic/failure reports (per-message failure details; not all receivers send these)
Both tags also accept an array of addresses (RFC 9989 — comma-separated list):
adkim() / aspf()
Alignment mode for DKIM and SPF respectively.
'relaxed'— the organisational domain must match (e.g.mail.example.comaligns withexample.com)'strict'— the domains must match exactly
Omitting either defaults to relaxed alignment per the RFC.
reporting()
Specifies which failure conditions trigger a forensic report. Accepts a string or an array of options:
| Value | fo tag |
Meaning |
|---|---|---|
'all' |
fo=0 |
Report if all mechanisms fail |
'any' |
fo=1 |
Report if any mechanism fails |
'dkim' |
fo=d |
Report if DKIM fails |
'spf' |
fo=s |
Report if SPF fails |
Multiple values produce a colon-separated fo tag:
Duplicate values are silently deduplicated. 'all' and 'any' are mutually exclusive — passing both throws an InvalidDmarcRecordException.
publicSuffixDomainPolicy()
Controls DMARC policy application at public suffix domains (DMARCbis extension).
'y'— apply DMARC policy to this public suffix domain'n'— do not apply policy to this public suffix domain'u'— undefined / unknown
testingMode()
When set to 'y', signals that DMARC is in testing mode. Receivers should not apply policy actions but may still send reports.
Validation
The package validates inputs on each setter call. Passing an invalid value throws a CbowOfRivia\DmarcRecordBuilder\Exceptions\InvalidDmarcRecordException. It extends the native \InvalidArgumentException, so existing catch (\InvalidArgumentException) handlers continue to work.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
- Charles Bowen
- All Contributors
License
The MIT License (MIT). Please see License File for more information.