An IT service provider have to write our SPF changes on Internet, I just mail my instructions.
I created a program in PHP to check in one click all my domains, to see if it is correct (sometimes a bad copy-paste include bad characters)
I tried to test the SPF with
if (strpos(strtolower($spf), 'v=spf')
but this doesn't check bad characters
I tried with a preg_match but it's not working
A spf record can contain only these characters [a-z] [0-9] . ? - ~ (space) and must start with v=spf
all other characters must echo "Invalid syntax"
Example:
$spfdata='v=spf1 mx 1.2.3.4 ~all';
if (preg_match('/(v=spf)([a-z0-9-~?.])/i', $spfdata)){
echo "SPF seems to be ok";
} else {
echo "Invalid syntax";
}
This doesn't work it always says "ok" even if I type a bad character.