YounG for You

don't be only father of your children

Fsockopen Error - Failed to Parse Address

| Comments

Just met this error when using MailPress plugin in WordPress. on file

"wp-content/plugins/mailpress/mp-includes/Swiftmailer/classes/Swift/Transport/StreamBuffer.php" Line 233

    if (!$this->_stream = fsockopen($host, $this->_params['port'], $errno, $errstr, $timeout))
    {
      throw new Swift_TransportException(
        'Connection could not be established with host ' . $this->_params['host'] .
        ' [' . $errstr . ' #' . $errno . ']'
        );
    }

Checked the php manual: fsockopen It says

1
resource fsockopen ( string $hostname [, int $port = -1 [, int &$errno [, string &$errstr [, float $timeout = ini_get("default_socket_timeout") ]]]] )

After some research, I found that we can’t leave the port parameter empty, although it is stated optional.

This can be traced to C function “parse_ip_address_ex”, it needs a colon to separate IP and port number in the textual address it is passed.

Refer from this topic

So the solution is simple, either add a port behind the server’s address, or specify a port as the second parameter.

Simple Solution
1
2
3
fsockopen('relay.xxx.com:25');
or
fsockopen('relay.xxx.com', 25);

Of course we won’t change the MailPress’s source code, just change the MailPress settings on the dashboard :)

Comments