title: Get the correct response from Yahoo SMTP
body: <p>I try to send a mail via php to an yahoo recipient.
  Every time I connect to yahoo I get a 250 status code for the recipient address, even if it doesn't exist. I found a script which get the correct status code from yahoo, but I cannot find the differences or mistakes I did in my script. I tried to send different commands and run the script on several servers, but I always get a 250 response for the RCPT-TO-command.
  Why do I don't get the correct response? I want to stop my script when a recipient doesn't exist!</p>
  
  <p>Log of verify-email.org which gets the correct response:</p>
  
  <pre>MX record about yahoo.com exists.
  Connection succeeded to g.mx.mail.yahoo.com SMTP.
  =220 mta1062.mail.sp2.yahoo.com ESMTP YSmtp service ready
  > HELO verify-email.org
  =250 mta1062.mail.sp2.yahoo.com
  > MAIL FROM: &lt;check@verify-email.org&gt;
  =250 sender &lt;check@verify-email.org&gt; ok
  > RCPT TO: &lt;sdjrfvn3r@yahoo.com&gt;
  =554 delivery error: dd This user doesn't have a yahoo.com account (sdjrfvn3r@yahoo.com) [0] - mta1062.mail.sp2.yahoo.com
  </pre>
  
  <p>Log of my script which gets the wrong response:</p>
  
  <pre>C Connect to h.mx.mail.yahoo.com
  S 220 mta1144.mail.mud.yahoo.com ESMTP YSmtp service ready
  C HELO my-domain.com
  S 250 mta1144.mail.mud.yahoo.com (152.70 ms)
  C MAIL FROM: &lt;existing-address@my-domain.com&gt;
  S 250 sender &lt;existing-address@my-domain.com&gt; ok (723.29 ms)
  C RCPT TO: &lt;sdjrfvn3r@yahoo.com&gt;
  S 250 recipient &lt;sdjrfvn3r@yahoo.com&gt; ok (152.67 ms)
  C Close socket connection
  S Connection closed gracefully
  </pre>
  
  <p>You can find the script which works properly here: <a href="http://verify-email.org" rel="nofollow">http://verify-email.org</a></p>
  
  <p>My script:
      
  
  <pre><code>    while(preg_match('/^\d\d\d-/', $r = fgets($sock))) {
          $response .= $r;
      }
      $response .= $r;
  
      return $response;
  }
  
  $mxRecord = "a.mx.mail.yahoo.com";
  $domain = 'example.com';
  $mailFrom = 'mailfrom@example.com';
  $rcptTo = 'doesntexist2011@yahoo.com';
  
  $commands = array(
      "HELO ".$domain."\r\n",
      "MAIL FROM: &lt;".$mailFrom."&gt;\r\n",
      "RCPT TO: &lt;".$rcptTo."&gt;\r\n",
  //  "DATA\r\n",
  //  ... email subject and content
  //  ".\r\n",
      "QUIT\r\n"
  );
  
  if($sock = fsockopen($mxRecord, 25, $errno, $errstr, 30)) {
      foreach($array as $cmd) {
          echo htmlentities($cmd);
          echo '&lt;br /&gt;';
          fwrite($sock, $cmd);
          echo htmlentities(getResponse($sock));
          echo '&lt;hr /&gt;';
      }
  
      fclose($sock);
  }
  else {
      echo 'no connection';
  }
  ?&gt;
  </code></pre>
  
  <p>Some information:</p>
  
  <ul><li>I used my own domain (not example.com)</li>
  <li>The script is located on the server where my domain refers to</li>
  <li>The server isn't on any blacklist like spamhaus.org</li>
  <li>The used mail address in "Mail From" does exist</li>
  <li>I use getmxrr() to get the mx entries of yahoo.com</li>
  <li>I tried HELO and EHLO -> always the same response</li></ul>