PHP code example of cbowofrivia / dmarc-record-builder
1. Go to this page and download the library: Download cbowofrivia/dmarc-record-builder library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cbowofrivia / dmarc-record-builder example snippets
use CbowOfRivia\DmarcRecordBuilder\DmarcRecord;
$record = (string) (new DmarcRecord())
->policy('reject')
->rua('mailto:[email protected] ');
// v=DMARC1; p=reject; rua=mailto:[email protected]
$record = new DmarcRecord();
$record->policy('reject')
->subdomainPolicy('quarantine')
->rua('mailto:[email protected] ')
->ruf('mailto:[email protected] ')
->adkim('relaxed')
->aspf('strict')
->reporting(['dkim', 'spf'])
->nonExistentSubdomainPolicy('reject')
->publicSuffixDomainPolicy('y')
->testingMode('n');
echo $record;
// v=DMARC1; p=reject; sp=quarantine; rua=mailto:[email protected] ; ruf=mailto:[email protected] ; adkim=r; aspf=s; fo=d:s; np=reject; psd=y; t=n
$record = new DmarcRecord(
version: 'DMARC1',
policy: 'reject',
subdomain_policy: 'quarantine',
rua: 'mailto:[email protected] ',
ruf: 'mailto:[email protected] ',
adkim: 'relaxed',
aspf: 'strict',
reporting: ['dkim', 'spf'],
np: 'reject',
psd: 'y',
t: 'n',
);
$record = (string) DmarcRecord::create(
policy: 'quarantine',
rua: 'mailto:[email protected] ',
);
// v=DMARC1; p=quarantine; rua=mailto:[email protected]
$record = DmarcRecord::parse('v=DMARC1; p=quarantine; adkim=r; aspf=s; fo=d:s');
$record->policy; // 'quarantine'
$record->adkim; // 'relaxed' (translated from 'r')
$record->aspf; // 'strict' (translated from 's')
$record->reporting; // ['dkim', 'spf'] (translated from 'fo=d:s')
$record = DmarcRecord::parse('v=DMARC1; p=none; rua=mailto:[email protected] ');
$record->policy('reject');
echo $record;
// v=DMARC1; p=reject; rua=mailto:[email protected]
->rua('mailto:[email protected] ')
->ruf('mailto:[email protected] ')
->rua(['mailto:[email protected] ', 'mailto:[email protected] '])
// rua=mailto:[email protected] ,mailto:[email protected]
->reporting(['dkim', 'spf'])
// fo=d:s
->reporting(['any'])
// fo=1
// Throws: Expected one of: "none", "quarantine", "reject", null. Got: "monitor"
$record->policy('monitor');
// Throws: rua mailto address should start with "mailto:"
$record->rua('[email protected] ');
// Throws: Expected one of: "relaxed", "strict", null. Got: "loose"
$record->adkim('loose');
// Throws: Reporting options "all" (0) and "any" (1) are mutually exclusive.
$record->reporting(['all', 'any']);