Jump to content

fsockopen() to SMTP server troubles.


haku

Recommended Posts

I'm trying to open a socket to an SMTP server. I am using the following code:

 

$smtp_connect = fsockopen($node->smtp_server, $node->smtp_port, $errno, $errstr, 10);
while (!feof($smtp_connect))
{
    $smtp_response .= fgets($smtp_connect, 4096);
}
echo $smtp_response;

 

In my php.ini, I set default_socket_timeout to 10 seconds. I am also setting it explicitly in the function call. However, the fsocketopen function doesn't seem to close properly.

 

I say this because when I take a timestamp at before the function call, and then again after the function call, the call itself takes 60 seconds. The response I get from th server (through fgets()) is the following:

 

220-<SMTP HOST> ESMTP Exim 4.69 #1 Thu, 22 Jul 2010 00:15:44 -0600

220-We do not authorize the use of this system to transport unsolicited,

220 and/or bulk e-mail.

421 <SMTP HOST>: SMTP command timeout - closing connection

So the connection is made (which is why I get the 220 response), but then because it doesn't end the function call after the connection is made, it times out.

 

Does anyone have any idea how to fix this? How can I force the function to stop after the socket has been opened successfully?

Link to comment
https://forums.phpfreaks.com/topic/208513-fsockopen-to-smtp-server-troubles/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.