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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.