【问题标题】:PHPMailer: Am I connected to external SMPT or not?PHPMailer:我是否连接到外部 SMTP?
【发布时间】:2020-02-04 13:07:04
【问题描述】:

我得到了以下由 PHPMailer 输出的日志:

2020-02-03 13:39:00 Connection: opening to some-external.smtp.host:25, timeout=300, options=array()
2020-02-03 13:39:00 Connection: opened
2020-02-03 13:39:00 SERVER -> CLIENT: 220-my-own.domain.com ESMTP Exim 4.92 #2 Mon, 03 Feb 2020 13:39:00 +0000 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2020-02-03 13:39:00 CLIENT -> SERVER: EHLO url-at-my-own.domain.com
2020-02-03 13:39:00 SERVER -> CLIENT: 250-url-at-my-own.domain.com Hello url-at-my-own.domain.com [31.186.175.24]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
2020-02-03 13:39:00 CLIENT -> SERVER: MAIL FROM:<info@domain.com>
2020-02-03 13:39:00 SERVER -> CLIENT: 250 OK
2020-02-03 13:39:00 CLIENT -> SERVER: RCPT TO:<recipient@hotmail.com>
2020-02-03 13:39:00 SERVER -> CLIENT: 550-Please turn on SMTP Authentication in your mail client. 550-(test.admin.mijnvolksuniversiteit.nl) [31.186.175.24]:50402 is not550 permitted to relay through this server without authentication.
2020-02-03 13:39:00 SMTP ERROR: RCPT TO command failed: 550-Please turn on SMTP Authentication in your mail client. 550-(url-at-my-own.domain.com) [31.186.175.24]:50402 is not550 permitted to relay through this server without authentication.
2020-02-03 13:39:00 CLIENT -> SERVER: QUIT
2020-02-03 13:39:00 SERVER -> CLIENT: 221 url-at-my-own.domain.com closing connection
2020-02-03 13:39:00 Connection: closed

现在,问题是“显而易见的”,服务器要求我验证自己,但这不是这里的问题。重要的是知道我是否真的连接到“some-external.smtp.host”或“my-own.domain.com”上的某个东西。

我正在与管理“some-external.smtp.host”的外部方打交道,该方声称我不需要进行身份验证,因为“my-own.domain.com”服务器 IP 已列入白名单。

他们特别声称我似乎已连接到本地 SMTP 服务器,因为第 3 行“SERVER -> CLIENT: 220-my-own.domain.com ESMTP Exim”中包含我自己的域名而不是他们的域名.

我相信,因为第 1 行特别声明与“some-external.smtp.host”建立了连接,第 2 行声明连接已成功打开,所以第 3 行中的 220 消息是外部主机(又名 SERVER ) 正在按其名称寻址本地服务器(又名 CLIENT)。

由于我没有对我的服务器的管理员访问权限,我正在寻找方法来找出谁就在这里。我真的希望排除我没有连接到本地的东西,而这确实是他们的服务器在阻止我。

用于启动PHPMailer的代码如下:

$mail = new PHPMailer(true);
                    try {
                        //Server settings
                        $mail->SMTPDebug = SMTP::DEBUG_CONNECTION;
                        $mail->isSMTP();
                        $mail->Host       = $this->vu['setting_mailrelay_host'];
                        if($this->vu['setting_mailrelay_username'] != '' && $this->vu['setting_mailrelay_password'] != '') {
                            $mail->SMTPAuth   = true;
                            $mail->Username   = $this->vu['setting_mailrelay_username'];
                            $mail->Password   = $this->vu['setting_mailrelay_password'];
                        }
                        $mail->SMTPSecure = $this->vu['setting_mailrelay_security'];
                        if($this->vu['setting_mailrelay_security'] == '') {
                            $mail->SMTPAutoTLS = false;
                        }
                        $mail->Port       = $this->vu['setting_mailrelay_port'];

                        //Recipients
                        $mail->setFrom($this->vu['email'], $this->vu['name']);
                        $mail->addAddress($email_to, trim($person['last_name']));
                        $mail->addReplyTo($this->vu['email'], $this->vu['name']);

                        // Content
                        $mail->isHTML(true);
                        $mail->Subject = $subject;
                        $mail->Body    = $mailBody;
                        $mail->AltBody = $message_plain;

                        $mail->send();
                        echo 'Message has been sent';
                    } catch (Exception $e) {
                        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
                    }

在我的例子中,SMTPAuth 是假的,用户名和密码是空的,因为外部方坚持我不需要进行身份验证。

SMTPSecure 为空且 SMTPAutoTLS 为 false,因为外部方坚持应关闭加密。

更新: 如果我启用 TLS,则日志如下:

2020-02-04 13:08:11 Connection: opening to some-external.smtp.host:25, timeout=300, options=array()
2020-02-04 13:08:11 Connection: opened
2020-02-04 13:08:11 SERVER -> CLIENT: 220-my-own.domain.com ESMTP Exim 4.92 #2 Tue, 04 Feb 2020 13:08:11 +0000 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2020-02-04 13:08:11 CLIENT -> SERVER: EHLO url-at-my-own.domain.com
2020-02-04 13:08:11 SERVER -> CLIENT: 250-my-own.domain.com Hello url-at-my-own.domain.com [31.186.175.24]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
2020-02-04 13:08:11 CLIENT -> SERVER: STARTTLS
2020-02-04 13:08:11 SERVER -> CLIENT: 220 TLS go ahead
2020-02-04 13:08:11 Connection failed. Error #2: stream_socket_enable_crypto(): Peer certificate CN=`my-own.domain.com' did not match expected CN=`some-external.smtp.host' [/home/tstvubo/public_html/vendor/phpmailer/phpmailer/src/SMTP.php line 429]
SMTP Error: Could not connect to SMTP host.
2020-02-04 13:08:11 CLIENT -> SERVER: QUIT
2020-02-04 13:08:12
2020-02-04 13:08:12
2020-02-04 13:08:12 Connection: closed

这会导致服务器抱怨两边的证书不匹配,好吧...如果我调整调用 PHP 代码以应用:

$mail->SMTPOptions = ['ssl' => [
    'verify_peer' => false,
    'verify_peer_name' => false,
    'allow_self_signed' => true
    ]
];

结果变成如下:

2020-02-04 13:12:51 Connection: opening to some-external.smtp.host:25, timeout=300, options=array ( 'ssl' => array ( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ),)
2020-02-04 13:12:51 Connection: opened
2020-02-04 13:12:51 SERVER -> CLIENT: 220-my-own.domain.com ESMTP Exim 4.92 #2 Tue, 04 Feb 2020 13:12:51 +0000 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2020-02-04 13:12:51 CLIENT -> SERVER: EHLO url-at-my-own.domain.com
2020-02-04 13:12:51 SERVER -> CLIENT: 250-my-own.domain.com Hello url-at-my-own.domain.com [31.186.175.24]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
2020-02-04 13:12:51 CLIENT -> SERVER: STARTTLS
2020-02-04 13:12:51 SERVER -> CLIENT: 220 TLS go ahead
2020-02-04 13:12:51 CLIENT -> SERVER: EHLO url-at-my-own.domain.com
2020-02-04 13:12:51 SERVER -> CLIENT: 250-my-own.domain.com Hello url-at-my-own.domain.com [31.186.175.24]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250 HELP
2020-02-04 13:12:51 CLIENT -> SERVER: MAIL FROM:<info@domain.com>
2020-02-04 13:12:52 SERVER -> CLIENT: 250 OK
2020-02-04 13:12:52 CLIENT -> SERVER: RCPT TO:<recipient@hotmail.com>
2020-02-04 13:12:52 SERVER -> CLIENT: 550-Please turn on SMTP Authentication in your mail client. 550-(url-at-my-own.domain.com) [31.186.175.24]:36810 is not550 permitted to relay through this server without authentication.
2020-02-04 13:12:52 SMTP ERROR: RCPT TO command failed: 550-Please turn on SMTP Authentication in your mail client. 550-(url-at-my-own.domain.com) [31.186.175.24]:36810 is not550 permitted to relay through this server without authentication.
2020-02-04 13:12:52 CLIENT -> SERVER: QUIT
2020-02-04 13:12:52 SERVER -> CLIENT: 221 my-own.domain.com closing connection
2020-02-04 13:12:52 Connection: closed

现在它再次要求身份验证。

由此得出以下结论:

  • 我肯定连接到外部 SMTP 服务器。

  • 尽管外部方声称,简单的 IP 白名单并不能解决问题。

  • 我需要一些身份验证凭据或适当的证书才能与之通信。

判决?

【问题讨论】:

  • $this-&gt;vu['setting_mailrelay_host'] 中有什么内容?无论如何,如果他们想让你忽略加密,我会忽略他们的服务。
  • 该值包含“some-external.smtp.host”。

标签: php email smtp phpmailer


【解决方案1】:

真正阅读错误消息总是一个非常非常好的主意,尤其是这一点:

Peer certificate CN='my-own.domain.com' did not match expected CN='some-external.smtp.host'

这意味着虽然您可能要求连接到 some-external.smtp.host(因为这是您在 Host 属性中输入的内容),但您实际上已连接到 my-own.domain.com

这通常是由于防火墙规则重定向 SMTP 流量 - 这也意味着 TLS 正在执行完全它的设计目的,并提醒您您的流量实际上受到了人为控制the-middle 攻击(通过您自己的防火墙),因此像往常一样,禁用证书验证是个坏主意。 the PHPMailer troubleshooting guide 涵盖了这个确切的问题。

所以他们说的是正确的;不是他们这样做——是你的邮件服务器要求身份验证,而不是他们的。

【讨论】:

  • 好吧,我什至打电话给“my-own.domain.com”服务器的主机,向他们解释了情况,他们告诉我只要我的主机名不是在他们的域上,“my-own.domain.com”上的 SMTP 服务器不可能不启动。但我想那不可能是真的。
  • 所以,TLS deffo 当然必须打开。所以这意味着我必须与对方争吵以安排匹配证书?
  • 对方没有做错任何事,他们将无法获得他人域的证书。您需要要求您的托管服务提供商停止拦截您的 SMTP 流量,因为很可能是他们这样做了。
  • 嗯好吧,奇怪的是。例如,当我以 mailtrap.io SMTP(使用 TLS 和凭据)为目标时,它工作得非常好。但是当我的目标是 smtp.office365.com(带有 TLS 和凭据)时,我会在 de 220 行中不断看到“my-own.domain.com”。
  • 天堂你死了。故障排除中关于 cPanel 的 WHM smtp 安全设置的评论是阻止我们的原因,我们禁用了它,它立即起作用。嘎。
猜你喜欢
  • 1970-01-01
  • 2014-06-13
  • 2015-08-09
  • 1970-01-01
  • 1970-01-01
  • 2012-05-24
  • 2018-09-01
  • 1970-01-01
相关资源
最近更新 更多