mailing from php

hello all -

recently i have discovered that we can no longer email out of php using whatever email we choose in the "From:" header unless that domain name has a matching TXT/SPF record. otherwise, several spamming agencies will flag your IP# as naughty.

the ultra-excellent interserver.net customer service provided me with this link to monitor how the spamming authorities feel we are doing.

so, here is what i am thinking - have a function that checks if the email address domain name has a matching TXT record that shares the same IP number.

basically, we are looking for this TXT record:
v=spf1 include:_spf.google.com ip4:199.231.184.26 ~all
and trying to see if that IP number matches ours.

so the results might look like this:
here is a php function i am proposing:
Code:
function checkForDomainEmailMatch()     {
                /*      usage:  emailAddress
                                emailAddress name(s)

                        returns:
                                From: mark@edwardsmark.com
                                -- or --
                                From: Marky Edwards <mark@edwardsmarkf.com>
                                ReplyTo: <mark@edwardsmark.com

                */
        $input = func_get_args();

        $emailAddr      = null          ;
        $personName     = null          ;
        $ipNbr          = null          ;
        $returnResult   = 'From: '      ;

                // did we get one parameter or several ?
        if  ( is_array($input)  )       {
                $emailAddr      = array_shift($input);
                $personName     = trim(implode (' ', $input));
        } else {
                $emailAddr      = $input        ;
        }

                // get the IP number
        if (  array_key_exists('SERVER_ADDR', $_SERVER) )       {
                        // are we running locally or through apache?
                $ipNbr = $_SERVER['SERVER_ADDR'];
        } else {
                $ipNbr = gethostbyname(gethostname());
        }

        $domain = preg_replace('/^.*@/','',$emailAddr); // strip out email prefix, just use domain name

        $ipNbrMatch = '/' . $ipNbr . '/' ;
        $dnsRecord =  dns_get_record($domain, DNS_TXT) ;
               //EXAMPLE:  v=spf1 include:_spf.google.com ip4:199.231.184.26 ~all
        $dnsRecordIpNbr = null;

        if  ( $dnsRecord && array_key_exists('txt', $dnsRecord[0] ))
                $dnsRecordIpNbr = $dnsRecord[0]['txt']  ;

        if  ( $personName )
                $returnResult   .=      $personName
                                .       '<'
                                ;

        if  ( $dnsRecordIpNbr && preg_match($ipNbrMatch, $dnsRecordIpNbr))      {
                $returnResult   .= $emailAddr
                                . '>'
                                ;
        } else {
                $domainName = null;
                                // looking for edwardsmarkf.info   ;-)
                $pattern[] = $ipNbrMatch;
                $pattern[] = '/ /';
                $domainName     = preg_replace($pattern, '', exec('head -1 /etc/hosts')) ;

                        // default email address
                $returnResult   .=      get_current_user()
                                .       '@'
                                .       $domainName
                                ;

                if  ( $personName )
                        $returnResult   .=      '>';

                $returnResult   .=      "\r\n"
                                .       'ReplyTo: '
                                ;

                if  ( $personName )     {
                        $returnResult   .=      $personName
                                        .       '<'
                                        ;
                }


                $returnResult   .=      $emailAddr      ;

                if  ( $personName )
                        $returnResult   .=      '>';

                $returnResult   .=      "\r\n"  ;
        }

        return $returnResult;
}
thoughts? concerns?
 
Last edited:

Quags

Administrator
Staff member
You may want to test the mailing itself, from php. There is the port 25 mail tester and check dkim and spf too.

  1. If you wish to receive the results at the address in the “mail_from,” the sample message should be sent to check-auth@verifier.port25.com.
  2. If you wish to receive the results at the address in the “from” header, the sample message should be sent to check-auth2@verifier.port25.com.
  3. If you wish to receive the results at a different address from one of the addresses above, the address need to be added to the check-auth address. For example, to send the results to:
    jsmith@yourdomain.com the sample message should be sent to check-auth-jsmith=yourdomain.com@verifier.port25.com.
A reply email will be sent back to you with an analysis of the message’s authentication status. The report will perform the following checks: SPF, SenderID, DomainKeys, DKIM and Spamassassin.
 
john - this looks very interesting. i am guessing one might include the following: (assuming edwardsmarky@gmail.com)
Code:
Bcc:  check-auth-edwardsmarky=gmail.com@verifier.port25.com
what do you think?

this writer also has a good suggestion. he suggested in gmail to just look at the "show original" and look for
Received-SPF: pass
Authentication-Results: ... spf=pass ... dkim=pass
 
Last edited:

Quags

Administrator
Staff member
This recently came up. If you see Domainkeys neutral on cpanel, note: DomainKeys was dropped in favor of DKIM. So you shouldn't expect to see a "pass" for the DomainKeys check.
 
Top