PHP 8.3 + Pear Mail fsockopen(): Unable to connect to mail.example.com:465 (Connection refused)
AnsweredI had to do a migration because the OS was done with security support. I migrated and I've had a lot of trouble sending email.
I've manually setup PHP Pear Mail:
- Auth_SASL-1.2.0
- Net_SMTP-1.12.1
- Net_Socket-1.2.1
- PEAR-1.10.15
...in order to send clean authenticated emails like on the previous server, On a minor note I have no idea if (and if so where) the PHP Pear Mail script might be on the server to begin with.
So I kept hitting an old error and was told I was running an old version, fine - I got the latest versions of everything until I hit a problem that wasn't a missing file:
fsockopen(): Unable to connect to mail.example.com:465 (Connection refused)
Further investigation in to this file:
/var/log/exim_mainlog
Revealed:
2024-07-02 05:13:12 TLS error on connection from [---.---.---.---]:43464 (SSL_accept): timed out
For further PHP debugging information please see the bottom this this post.
So most the solutions for the problems I've encountered are things I end up fixing through WHM. There are firewalls and other security software/plugins/etc. I've read on a Plesk thread that Imunify360 can disable sending emails except for specified Linux users though that option was disabled. I looked through the software listed under plugins. I looked through Exim related pages.
So I'm at a loss as to what is blocking the email from being sent. Worse yet, every test completely locks up the server for 10 minutes short of me forcing a reboot.
Yes, Exim is listening on port 465 apparently:
[root@server:/root]$ netstat -lnp
tcp 0 0 0.0.0.0:465 0.0.0.0:* LISTEN 317/exim
tcp 0 0 0.0.0.0:465 0.0.0.0:* LISTEN 317/exim
tcp6 0 0 :::465 :::* LISTEN 317/exim
I would be very grateful if I could get some help on this migration is threatening to envelope two entire weeks of my time.
[0] => Array
(
[function] => error_handle
[args] => Array
(
[0] => 2
[1] => fsockopen(): Unable to connect to mail.example.com:465 (Connection refused)
[2] => /[__SERVER__PATH__]/php/Net/Socket.php
[3] => 185
))
[1] => Array
(
[file] => /[__SERVER__PATH__]/php/Net/Socket.php
[line] => 185
[function] => fsockopen
[args] => Array
(
[0] => mail.example.com
[1] => 465
[2] => 0
[3] =>
[4] => 60
))
[2] => Array
(
[file] => /[__SERVER__PATH__]/php/Net/SMTP.php
[line] => 474
[function] => connect
[class] => Net_Socket
[object] => Net_Socket Object
(
[_debug] =>
[_default_error_mode] =>
[_default_error_options] =>
[_default_error_handler] =>
[_error_class] => PEAR_Error
[_expected_errors] => Array
(
)[fp] =>
[blocking] => 1
[persistent] =>
[addr] => mail.example.com
[port] => 465
[timeout] =>
[lineLength] => 2048
[newline] =>)
[type] => ->
[args] => Array
(
[0] => mail.example.com
[1] => 465
[2] =>
[3] => 60
[4] => Array
(
))
)
[3] => Array
(
[file] => /[__SERVER__PATH__]/php/Mail/smtp.php
[line] => 449
[function] => connect
[class] => Net_SMTP
[object] => Net_SMTP Object
(
[host] => mail.example.com
[port] => 465
[localhost] => localhost
[auth_methods] => Array
(
[SCRAM-SHA-512] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA512
)[SCRAM-SHA-384] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA384
)[SCRAM-SHA-256] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA256
)[SCRAM-SHA-224] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA224
)[SCRAM-SHA-1] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA1
)[DIGEST-MD5] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authDigestMD5
)[CRAM-MD5] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authCramMD5
)[LOGIN] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authLogin
)[PLAIN] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authPlain
)[XOAUTH2] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authXOAuth2
)[OAUTHBEARER] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authOAuthBearer
))
[pipelining] =>
[pipelined_commands:protected] => 0
[debug:protected] =>
[debug_handler:protected] =>
[socket:protected] => Net_Socket Object
(
[_debug] =>
[_default_error_mode] =>
[_default_error_options] =>
[_default_error_handler] =>
[_error_class] => PEAR_Error
[_expected_errors] => Array
(
)[fp] =>
[blocking] => 1
[persistent] =>
[addr] => mail.example.com
[port] => 465
[timeout] =>
[lineLength] => 2048
[newline] =>)
[socket_options:protected] => Array
(
)[timeout:protected] => 0
[code:protected] => -1
[arguments:protected] => Array
(
)[greeting:protected] =>
[esmtp:protected] => Array
(
)[gssapi_principal:protected] =>
[gssapi_cname:protected] =>
[scram_sha_hash_algorithm:protected] =>
)[type] => ->
[args] => Array
(
[0] =>
))
[4] => Array
(
[file] => /[__SERVER__PATH__]/php/Mail/smtp.php
[line] => 332
[function] => getSMTPObject
[class] => Mail_smtp
[object] => Mail_smtp Object
(
[sep] =>[_smtp] => Net_SMTP Object
(
[host] => mail.example.com
[port] => 465
[localhost] => localhost
[auth_methods] => Array
(
[SCRAM-SHA-512] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA512
)[SCRAM-SHA-384] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA384
)[SCRAM-SHA-256] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA256
)[SCRAM-SHA-224] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA224
)[SCRAM-SHA-1] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA1
)[DIGEST-MD5] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authDigestMD5
)[CRAM-MD5] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authCramMD5
)[LOGIN] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authLogin
)[PLAIN] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authPlain
)[XOAUTH2] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authXOAuth2
)[OAUTHBEARER] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authOAuthBearer
))
[pipelining] =>
[pipelined_commands:protected] => 0
[debug:protected] =>
[debug_handler:protected] =>
[socket:protected] => Net_Socket Object
(
[_debug] =>
[_default_error_mode] =>
[_default_error_options] =>
[_default_error_handler] =>
[_error_class] => PEAR_Error
[_expected_errors] => Array
(
)[fp] =>
[blocking] => 1
[persistent] =>
[addr] => mail.example.com
[port] => 465
[timeout] =>
[lineLength] => 2048
[newline] =>)
[socket_options:protected] => Array
(
)[timeout:protected] => 0
[code:protected] => -1
[arguments:protected] => Array
(
)[greeting:protected] =>
[esmtp:protected] => Array
(
)[gssapi_principal:protected] =>
[gssapi_cname:protected] =>
[scram_sha_hash_algorithm:protected] =>
)[_extparams] => Array
(
)[host] => mail.example.com
[port] => 465
[starttls] =>
[auth] => 1
[username] => [valid_fromt_email @ address.tld]
[password] => -------------------------
[localhost] => localhost
[timeout] =>
[debug] =>
[debug_handler] =>
[greeting] =>
[persist] =>
[pipelining] =>
[socket_options] => Array
(
)[response] =>
[queued_as] =>
)[type] => ->
[args] => Array
(
))
[5] => Array
(
[file] => /[__SERVER__PATH__]/php/Mail/smtp.php
[line] => 319
[function] => send_or_fail
[class] => Mail_smtp
[object] => Mail_smtp Object
(
[sep] =>[_smtp] => Net_SMTP Object
(
[host] => mail.example.com
[port] => 465
[localhost] => localhost
[auth_methods] => Array
(
[SCRAM-SHA-512] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA512
)[SCRAM-SHA-384] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA384
)[SCRAM-SHA-256] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA256
)[SCRAM-SHA-224] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA224
)[SCRAM-SHA-1] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authScramSHA1
)[DIGEST-MD5] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authDigestMD5
)[CRAM-MD5] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authCramMD5
)[LOGIN] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authLogin
)[PLAIN] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authPlain
)[XOAUTH2] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authXOAuth2
)[OAUTHBEARER] => Array
(
[0] => Net_SMTP Object
*RECURSION*
[1] => authOAuthBearer
))
[pipelining] =>
[pipelined_commands:protected] => 0
[debug:protected] =>
[debug_handler:protected] =>
[socket:protected] => Net_Socket Object
(
[_debug] =>
[_default_error_mode] =>
[_default_error_options] =>
[_default_error_handler] =>
[_error_class] => PEAR_Error
[_expected_errors] => Array
(
)[fp] =>
[blocking] => 1
[persistent] =>
[addr] => mail.example.com
[port] => 465
[timeout] =>
[lineLength] => 2048
[newline] =>)
[socket_options:protected] => Array
(
)[timeout:protected] => 0
[code:protected] => -1
[arguments:protected] => Array
(
)[greeting:protected] =>
[esmtp:protected] => Array
(
)[gssapi_principal:protected] =>
[gssapi_cname:protected] =>
[scram_sha_hash_algorithm:protected] =>
)[_extparams] => Array
(
)[host] => mail.example.com
[port] => 465
[starttls] =>
[auth] => 1
[username] => [valid_fromt_email @ address.tld]
[password] => -------------------------
[localhost] => localhost
[timeout] =>
[debug] =>
[debug_handler] =>
[greeting] =>
[persist] =>
[pipelining] =>
[socket_options] => Array
(
)[response] =>
[queued_as] =>
)[type] => ->
[args] => Array
(
[0] => [valid to email @ address.tld]
[1] => Array
(
[MIME-Version] => 1.0
[Date] => Tue, 02 Jul 2024 12:17:44 +0000
[From] => <[valid_fromt_email @ address.tld]>
[Subject] => Contact from John
[To] => [valid to email @ address.tld]
[Content-Type] => multipart/alternative;
boundary="=_5d80c22efa979cad342450dbe04c818d"
)[2] => --=_5d80c22efa979cad342450dbe04c818d
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1[removed]
--=_5d80c22efa979cad342450dbe04c818d
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1[removed]
)
)
-
Hi,
Do you have SMTP Restrictions (WHM > SMTP Restrictions) enabled? Or, if using CSF, SMTP_BLOCK? Either of those settings could interfere with mail scripts that use remote servers to send email.
If the error persists with those settings disabled, I'd suggest checking the firewall. If the script is connecting to a remote server, it may indicate port 465 is blocked either server.
0 -
We ended up doing two things.
First, we ripped out Immunity360 since it kept insisting that legitimate mail was spam. It's not properly developed as there was an overwhelming amount of ambiguity.
Secondly there were two parts of the authentication that were off.
I had to change the server host from "example.com" to "tils://example.com". Additionally somehow the @example.com part of the username was lost in translation.
Everything is back to working as it should be.
0
Please sign in to leave a comment.
Comments
2 comments