使用 PHPMailer SMTP 无法连接 host
在后台是可以正常发送邮件的,但使用 PHPMailer 编程方式出现连接 host 失败: SMTP Error: Could not connect to SMTP host. Failed to connect to server SMTP server error: Failed to connect to server SMTP code: 111 Additional SMTP info: Connection refused
例子代码:
$this->mailer = new PHPMailer(true);
$this->mailer->CharSet = 'UTF-8';
$this->mailer->isSMTP();
$this->mailer->SMTPDebug = 0;
$this->mailer->SMTPAuth = true;
$this->mailer->SMTPSecure = 'ssl';
$this->mailer->Host = 'mail.domain.xyz';
$this->mailer->Port = 465;
$this->mailer->Username = '[email protected]';
$this->mailer->Password = 'Nr7Fx3FxlGyknsPK';
$this->mailer->setFrom('[email protected]', 'test');
Did you check the dovecot log?
Try execute command tail -n 100 logs/dovecot/mail.log on your BillionMail project directory when you encountered authentication errors.
Did you check the dovecot log?
Try execute command
tail -n 100 logs/dovecot/mail.logon your BillionMail project directory when you encountered authentication errors.
感谢您的回复,下面是 logs/dovecot/mail.log 的内容:
2025-06-06T06:52:31.805488+00:00 dovecot dovecot: imap-login: Disconnected: Connection closed (no auth attempts in 8 secs): user=<>, rip=167.94.138.119, lip=172.66.1.5, TLS: Connection closed, session=<znGdrOE2SJunXop3>
2025-06-06T06:52:39.934318+00:00 dovecot dovecot: imap-login: Disconnected: Connection closed (no auth attempts in 3 secs): user=<>, rip=167.94.138.119, lip=172.66.1.5, TLS, session=<73wZreE2LIenXop3>
2025-06-06T06:52:44.197236+00:00 dovecot dovecot: imap-login: Disconnected: Connection closed: SSL_accept() failed: error:0A000102:SSL routines::unsupported protocol (no auth attempts in 2 secs): user=<>, rip=167.94.138.119, lip=172.66.1.5, TLS handshaking: SSL_accept() failed: error:0A000102:SSL routines::unsupported protocol, session=<7ohareE25IKnXop3>
2025-06-06T06:52:50.062247+00:00 dovecot dovecot: imap-login: Disconnected: Connection closed: SSL_accept() failed: error:0A000102:SSL routines::unsupported protocol (no auth attempts in 3 secs): user=<>, rip=167.94.138.119, lip=172.66.1.5, TLS handshaking: SSL_accept() failed: error:0A000102:SSL routines::unsupported protocol, session=<Jge0reE28oKnXop3>
2025-06-06T06:52:53.214911+00:00 dovecot dovecot: imap-login: Disconnected: Connection closed: SSL_accept() failed: error:0A00018C:SSL routines::version too low (no auth attempts in 1 secs): user=<>, rip=167.94.138.119, lip=172.66.1.5, TLS handshaking: SSL_accept() failed: error:0A00018C:SSL routines::version too low, session=<FiLkreE2NOynXop3>
Please check your SMTP connection with TLS, execute the command below:
openssl s_client -connect your-server.com:465 -starttls smtp
Let me know what your encountered.
运行后的结果:
openssl s_client -connect mail.mydomain.xyz:465 -starttls smtp
CONNECTED(00000003)
Didn't find STARTTLS in server response, trying anyway...
write:errno=32
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 33 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---
Did you setup SSL for domain? If not, please apply on BillionMail and try again. I was give you a incorrect command before, try to execute command below:
openssl s_client -connect your-server.com:465
我有在后台申请了域名免费证书。
openssl s_client -connect mail.mydomain.xyz:465
CONNECTED(00000003)
depth=2 C = US, O = Internet Security Research Group, CN = ISRG Root X1
verify return:1
depth=1 C = US, O = Let's Encrypt, CN = R10
verify return:1
depth=0 CN = mail.mydomain.xyz
verify return:1
---
Certificate chain
0 s:CN = mail.mydomain.xyz
i:C = US, O = Let's Encrypt, CN = R10
a:PKEY: rsaEncryption, 2048 (bit); sigalg: RSA-SHA256
v:NotBefore: Jun 3 12:16:54 2025 GMT; NotAfter: Sep 1 12:16:53 2025 GMT
1 s:C = US, O = Let's Encrypt, CN = R10
i:C = US, O = Internet Security Research Group, CN = ISRG Root X1
a:PKEY: rsaEncryption, 2048 (bit); sigalg: RSA-SHA256
v:NotBefore: Mar 13 00:00:00 2024 GMT; NotAfter: Mar 12 23:59:59 2027 GMT
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIE+TC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US/txIbFcA8g3bc+P+AAAAGXNe6upQAABAMARzBFAiAO
hP+9ZIipYWZLjFWjqaiSvVFG1FrVvbMHc28Xccvo2gIhAPDpCyNdOpOrbgEx4SKP
lLnXlUdIeIgtX8QaRJHZ5vWPAHUA3dzKNJXX4RYF55Uy+sef+D0cUN/bADoUEnYK
LKy7yCoAAAGXNe6+kgAABAMARjBEAiAN/hXrc3AVSL3jpaGqRwSaGREh5mtu6t6B
SS/krQKe9wIgeG7VOVZWweEm0FZxzJRq/vZfA+Mn063IPJwe0cpc0OMwDQYJKoZI
hvcNAQELBQADggEBADrFeZitzxVMYUPxKSaCj3fhLa5CpxVq/J981DjEII9a+1K9
VsG5eikfVfckpLvi408vdx942/doYqJMAQ8efdtV7tpitez7uKsz9H7rlw8SzWWR
N9VpyWZo6BJrPs4nWyiHTggfPyjxll265+fwn+NfDMgRrjXzx4IyiIQx9rqmLNeL
kqpUNXRl1M4Q79FVV0draKMWpM6qvKIOsE9AZkPPhS8G3aNcqTUDr7tN6glls85W
Smxm1Edp6qxXQ6JYtqMeQWxSLU5Z2XMt/6p0sIL6AmI8ebfTT3Jxrl9slNRA4fXC
fgS0KMC2zqYkdjDfbJnwtYd2Q2H2vbWArOtTIg4=
-----END CERTIFICATE-----
subject=CN = mail.mydomain.xyz
issuer=C = US, O = Let's Encrypt, CN = R10
---
No client certificate CA names sent
Peer signing digest: SHA256
Peer signature type: RSA-PSS
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 3131 bytes and written 397 bytes
Verification: OK
---
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
Server public key is 2048 bit
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---
---
Post-Handshake New Session Ticket arrived:
SSL-Session:
Protocol : TLSv1.3
Cipher : TLS_AES_256_GCM_SHA384
Session-ID: 403BF10ADAB79A941F89D767E9A9F4CD88E9BF6A5F13480507927D3AF7F35955
Session-ID-ctx:
Resumption PSK: 34D981C32BF5FFBFA51A60249DF30D0695BC7C1F5B27DE75EFF2776F59A16EF5B98BA34E0F17608457A6647D46E55FA9
PSK identity: None
PSK identity hint: None
SRP username: None
TLS session ticket lifetime hint: 7200 (seconds)
TLS session ticket:
0000 - 8c e8 db 51 ae 77 45 12-47 83 fe 13 9b e3 d2 98 ...Q.wE.G.......
0010 - bc 41 82 18 fc bf c4 f5-85 46 6b d6 60 77 74 0f .A.......Fk.`wt.
0020 - 2a dd e8 84 56 c5 fd ac-ab bb ad 3d ed 97 0e 89 *...V......=....
0030 - 2d df 1f ea 67 29 ff 04-a8 cd ca f7 c2 f5 02 74 -...g).........t
0040 - 6d 1d ca 92 0d c6 ac 65-dd 01 13 9c bd a6 9e b8 m......e........
0050 - 19 3c 56 fc 2b 43 19 42-99 64 2c c2 cd e7 b8 91 .<V.+C.B.d,.....
0060 - d7 96 2b 9e f2 eb b8 8d-85 ef d7 83 1b f2 81 6a ..+............j
0070 - 29 e6 60 9d 9f 81 a7 d5-57 51 c2 3b 2b 2a 29 64 ).`.....WQ.;+*)d
0080 - c1 ab 5f 47 df 04 d2 81-73 1f bf 98 16 64 08 b6 .._G....s....d..
0090 - 7a 63 51 46 e2 5d 76 d2-3d 43 a1 ef 6c 80 dc ed zcQF.]v.=C..l...
00a0 - e0 e7 d7 5c 7d 32 c6 16-68 0c 3d da c8 0c a3 a2 ...\}2..h.=.....
00b0 - f3 6d 18 46 b0 b5 de 43-b5 4f d5 2b 3d a3 7d a0 .m.F...C.O.+=.}.
00c0 - 74 c5 94 3c 80 bc 79 c2-a2 89 76 66 ee 97 71 22 t..<..y...vf..q"
00d0 - e7 2d 16 b6 6d f5 27 ce-84 00 6b f6 d1 1d 0c 07 .-..m.'...k.....
00e0 - 7c 90 23 7c 7d f7 82 2e-ce b3 95 3f 8c 3c f9 da |.#|}......?.<..
Start Time: 1749288465
Timeout : 7200 (sec)
Verify return code: 0 (ok)
Extended master secret: no
Max Early Data: 0
---
read R BLOCK
220 mail.billionmail.com ESMTP Postfix
Look likes working well, can you provide your smtp info to our support email? [email protected].
I have the same problem, do you have a solution to the bug?