• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2027
  • Last Modified:

Strange SMTP problem

Ok, here's one that's got my mind wrapped up in a few knots.

I just wrote a script to check if an email address actually exists so that (after testing) I can implement it into my site's registration page & other mailer routines already in place on the site.

Here is the code for my script;

<?php
  $addr = $_GET['addr'];   //manually put into the url for testing purposes
  $parts = explode("@", $addr);
  $acct = $parts[0];
  $dom = $parts[1];
  $mail_from = "admin@mydomain.tld";

  // Check that MX(mail exchanger) record exists in domain check.
  // checkdnsrr function reference : http://www.php.net/manual/en/function.checkdnsrr.php
  if(checkdnsrr($dom, "MX"))
  {
    echo "Confirmation : MX record for $dom exists.<br>";
    // If MX record exists, save MX record address.
    // getmxrr function reference : http://www.php.net/manual/en/function.getmxrr.php
    if(getmxrr($dom, $MXHost))
    {
      echo "Confirmation : Confirming address by MX LOOKUP.<br>";
      for ( $i = 0,$j = 1; $i < count ( $MXHost ); $i++,$j++ )
      {
        echo "Result($j) - " . $MXHost[$i] . "<BR>";
      }
    }

    $sock = fsockopen($MXHost[0], 25, $errno, $errstr, 30);
    if($sock)
    {
      print "Connection established to $dom on server " . $MXHost[0] . "<br>\n";
      if(socket_set_blocking($sock, true))
      {
        print "Blocking mode enabled<br>";
        print "<p>Sending: HELO " . $_SERVER['HTTP_HOST'] . "<br>";
        fputs($sock, "HELO " . $_SERVER['HTTP_HOST'] . "\r\n");
        print fgets($sock, 1024) . "<br>"; // Display server's response.

        print "Sending: MAIL FROM: &lt;$mail_from&gt;<br>";
        fputs($sock, "MAIL FROM: <$mail_from>\r\n");
        print fgets($sock, 1024) . "<br>"; // Display server's response.

        print "Sending: RCPT TO: &lt;$addr&gt;<br>";
        fputs($sock, "RCPT TO: <$addr>\r\n");
        print fgets($sock, 1024) . "<br>"; // Display server's response.

        print "Sending: QUIT<br>";
        fputs($sock, "QUIT\r\n");
        print fgets($sock, 1024) . "<br>"; // Display server's response.
      }
      else
      {
        print "Blocking mode unable to be set<br>";
      }
    }
    else
    {
      print "Connection failed to $dom<br>\n";
    }
            
    print (fclose($sock)) ? "Socket successfully closed<br>" : "Socket failed to close<br>";
  }      
?>

Ok, here's the strange part now...the script actually works great on 95% of the all mail servers I tried. Testing was done using actual addresses from our site's member table, so the addresses are confirmed as good already, but when I try testing only certain addresses (the one below was one that failed the test with those results), I keep getting the following error message returned back from the mailserver in question;

Sending: HELO www.mydomain.tld
503 5.5.0 : Client host rejected: Improper use of SMTP command pipelining
Sending: MAIL FROM: <admin@mydomain.tld>
503 5.7.0 Error: access denied for myserver.net[xx.xx.xxx.105]
Sending: RCPT TO: <demonlover@netti.fi>
503 5.7.0 Error: access denied for myserver.net[xx.xx.xxx.105]
Sending: QUIT
503 5.7.0 Error: access denied for myserver.net[xx.xx.xxx.105]
Socket successfully closed

Yet if I check a Yahoo or Hotmail address or just about most other mailservers, I get a nice set of 250 responses back showing that each command was accepted just fine.

Not quite sure how to troubleshoot this one, or perhaps this is totally on the remote mailserver's side and there's nothing I can do. Any ideas would be of great help.

Thanks everyone, looking forward to what becomes of this :)
0
Richard Davis
Asked:
Richard Davis
  • 2
1 Solution
 
AndyAelbrechtCommented:
SMTP command pipelining is an addition to the standard; most servers don't really care about this, but it's one of the first filters against spam (apparantly, check http://www.wsrcc.com/spam/bounce.html for the exact explanation).

I do not exactly know however, how you could solve this fast.
a good start however, could be looking at ones the php smtp classes, like for example this one: http://freshmeat.net/projects/smtpclass/
the author notes that you can use SMTP command pipelining with this class, so I think a quick thrawl through this class might give you all you need to know to get it working.

hope it helps,

Andy
0
 
Richard DavisSenior Web DeveloperAuthor Commented:
Hi Andy,

First, thanks for the response.

I'll look into that freshmeat class. For the time being, I'm primarily interested in only running a basic test via SMTP to just authenticate that a submitted email account is, in fact, real. I'm trying to work on a way of checking addresses for validity as well as being able to notifiy the client of a delivery failure when they try to send an ecard. Currently, all emails are 100% originated by my server, so the client has not true direct access to my SMTP server, therefore, they have no direct connection to any mail delivery responses I receive as a result of their card not having made it to it's destination.

Also, during the registration phase, I am hoping to use this method as a way of pre-qualifying the client to ensure that when the server sends them their account activation mailer, that it is going to a valid address. I guess this would just be a more anal level of form validation.

Anyway, you get the idea behind what I am trying to acheive. My current mailer class seems to work fine, so I don't have a need to replace it with another class, just pggy back everything with a good SMTP communication handler. So, I'll have a peek at that one you submitted and let you know what I found. :)

Thanks again, Andy

~Adrian
0
 
Richard DavisSenior Web DeveloperAuthor Commented:
It would appear that I am going to need to really dig into this one. I'm guessing that I am going to have to really study SMTP command pipelining to better understand how it is that I could be causing their mailservers to spit back those responses. This one is definitely going to be a real brainwracking issue I can see.

I'm going to award you the point though for having at least given this a fair try at resolving it.

Take care & thanks again, Andy
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now