webo3/smtp-email-validation

模拟SMTP连接以验证电子邮件地址的存在。

dev-master / 1.0.x-dev 2024-02-19 21:48 UTC

This package is auto-updated.

Last update: 2024-09-19 23:20:52 UTC


README

这是一个PHP类,用于验证远程SMTP服务器上是否存在电子邮件地址。当您发送多封邮件时,这可以帮助您在邮件退回之前发送到无效的电子邮件地址。

  • 需要PHP的fsockopen、getmxrr功能,以及能够连接到远程端口25。

工作原理

include("vendor/autoload.php");

$response = \webO3\SmtpEmailValidation\Validator::test('user@domain.from', 'user@domain.to');
echo "<pre>".print_r($response, true)."</pre>";

我们首先获取要发送的电子邮件的MX记录,然后根据优先级依次连接到找到的MX记录,以验证是否可以连接。然后我们通过向服务器发送命令来模拟真实的SMTP连接,查看服务器将如何响应。

我们将收到如下响应:

Array
(
    [code] => 10
    [success] => false
    [msg] => Could not find any MX record associated with the domain.
)

Array
(
    [code] => 15
    [success] => false
    [msg] => Could not connect to any MX servers, they maybe down.
)

Array
(
    [code] => 20,
    [success] => false
    [msg] => Server connexion timeout. They maybe connexion protection in place.
)

Array
(
    [code] => 25,
    [success] => false
    [msg] => Server did not return a 220 response code.
)

Array
(
    [code] => 250,
    [success] => true
    [msg] => Email is valid.
)

Array
(
    [code] => 451 ou 452,
    [success] => true
    [msg] => The server rejected the email temporary, this indicate that greylisting is in use.
)

Array
(
    [code] => 451 ou 452,
    [success] => false
    [msg] => The server rejected the email address.
)

警告

许多托管提供商或ISP不允许您直接连接到远程端口25。

您需要设置发件地址为要用于发送电子邮件的地址,请注意,某些黑名单可能已经针对特定的FROM电子邮件地址设置。