mlocati / spf-lib

PHP library to parse, build and validate SPF (Sender Policy Framework) DNS records
MIT License
49 stars 6 forks source link

Are there any problems with ip6 records? #31

Closed ITC-KEDA closed 1 year ago

ITC-KEDA commented 1 year ago

My code: $decoder = new \SPFLib\Decoder(); try { $record = $decoder->getRecordFromDomain($input); } catch (\SPFLib\Exception $x) { $text ="There are problems with getting the SPF, or it can't be decoded"; }

print_r($record->getMechanisms());

My php script just stop, whengetting to: print_r($record->getMechanisms());, when there are ip6 record in the spf.

ITC-KEDA commented 1 year ago

Sorry, no thats working. Just tested it with another. SPF. And that works fine. So must be something else.

ITC-KEDA commented 1 year ago

I found root issues, i have this SPF: (IP address have been removed) v=spf1 ip4:x.x.x.x ip4:x.x.x.x ip6: xxxx:xxxx:xxxx::/48 include:u123456.wl.sendgrid.net ~all

The problems where that there where are space between ip6 and the ipv6 address. Therefor i got this in my log: HP Fatal error: Uncaught SPFLib\Exception\InvalidTermException: The SPF record contains an unrecognized term: ip6: in /var/www/clients/client11/web90/web/vendor/mlocati/spf-lib/src/Decoder.php:173

Could it be posible to get a error on these kind of error, instead of a php fatal error?

mlocati commented 1 year ago

Could it be posible to get a error on these kind of error, instead of a php fatal error?

You can simply catch the exception:

try {
   /// place your code here
} catch (\SPFLib\Exception\InvalidTermException $x) {
   // do whatever you want with the error described by $x
}