0

On this thread: How to detect if domain has catch all policy to accept email? Sachin Dane explains how to verify if a host behave like a "catch-all" domain using telnet.

I need to make this exact same verification but only using PHP, does anyone have this snippet somewhere ? or know the logic and functions to use to get this done ?

(I'm not looking for 3rd party services here, only the pure PHP solution)

Thanks a lot

I've tried to connect to SMTP host/port with fsockopen and then read some data using fgets in order to read the SMTP server response, but nothing shows up

<?php 
$port = 465;
$host = "mail.gmx.com";
$hostip = @gethostbyname($host);

if ($handler = @fsockopen($hostip, $port, $errno, $errstr, 2)){ 
   $buffer = fgets($handler, 50);//arbitrarily 50 bytes
   echo $buffer;
}
?>

As a result my buffer stays always empty and i have no clue if this is even the right start.

Jay Cohen
  • 193
  • 2
  • 9
  • 3
    Port 465 is encrypted with implicit SSL, that is why `fgets()` does not work. The server is waiting for you to initiate an SSL handshake first, and no SMTP communication is exchanged until the handshake is completed. Use port 25 or 587 instead. The answer you linked to uses port 25. – Remy Lebeau Jul 15 '19 at 17:58
  • Indeed thx. Now i face the issue that the function fgets freeze until timeout if i try to read a byte more than the server answered, so i have no way to read until "end of the buffer" nor to predict how long will be the message – Jay Cohen Jul 15 '19 at 22:15
  • SMTP uses CRLF-delimited lines. Read one byte at a time until you reach the LF. Which is exactly what `fgets()` does. 50 is a pretty small buffer size, though. – Remy Lebeau Jul 15 '19 at 23:03

0 Answers0