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;

  $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 :
  if(checkdnsrr($dom, "MX"))
    echo "Confirmation : MX record for $dom exists.<br>";
    // If MX record exists, save MX record address.
    // getmxrr function reference :
    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);
      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.
        print "Blocking mode unable to be set<br>";
      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[]
Sending: RCPT TO: <>
503 5.7.0 Error: access denied for[]
Sending: QUIT
503 5.7.0 Error: access denied for[]
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 :)
LVL 12
Richard DavisSenior Web DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 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:
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,


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.