phpexperts/neverbounce

NeverBounce API 的快速简单客户端。

v2.2.0 2020-05-14 23:28 UTC

This package is auto-updated.

Last update: 2024-09-10 18:06:22 UTC


README

TravisCI Maintainability Test Coverage

NeverBounce 客户端是 PHP Experts, Inc. 的一个项目,旨在轻松访问 NeverBounce API。

安装

通过 Composer

composer require phpexperts/neverbounce

用法

验证单个电子邮件地址

    // Build the client.
    $client = NeverBounceClient::build();
    
    // Quickly determine if an email is valid or not.
    $response = $client->isValid('theodore@phpexperts.pro');
    // Output: true or false
    
    // Get details as to why an email is valid or not.
    $emailValidationDTO = $client->validate('doesnt-exist@gmail.com');

    /* Output: 
    {
      +"status": "success"
      +"result": "invalid"
      +"flags": array:4 [
        0 => "free_email_host"
        1 => "has_dns"
        2 => "has_dns_mx"
        3 => "smtp_connectable"
      ]
      +"suggested_correction": ""
      +"execution_time": 309
    }
    */

批量电子邮件地址验证

    // Build the client.
    $client = NeverBounceClient::build();

    // Create the job over at NeverBounce.
    $jobId = $client->bulkVerify(['support@neverbounce.com', 'sales@phpexperts.pro']);
    
    // Periodicly check the job for results.
    for ($a = 0; $a < 30; ++$a) {
        $bulkValidationDTO = $client->checkJob($jobId);
        if (!$bulkValidationDTO) {
            sleep(1);
        }
        
        break;
    }
    
    /** Output:
    BulkValidationDTO [
        'status'           => 'success',
        'id'               => 2917483,
        'job_status'       => 'complete',
        'filename'         => 'bulk-1559703280.csv',
        'created_at'       => Carbon: '2019-06-04 22:54:41',
        'started_at'       => Carbon: '2019-06-04 22:54:42',
        'finished_at'      => Carbon: '2019-06-04 22:54:47',
        'total'            => ListStatsDTO [
            'records'    => 7,
            'billable'   => 5,
            'processed'  => 7,
            'valid'      => 3,
            'invalid'    => 3,
            'catchall'   => 1,
            'disposable' => 0,
            'unknown'    => 0,
            'duplicates' => 1,
            'bad_syntax' => 1,
        ],
        'bounce_estimate'  => 28.571428571429,
        'percent_complete' => 100,
        'execution_time'   => 12,
    ]
     */

所有 DTO 都可以轻松转换为数组、JSON,并且可序列化。有关详细信息,请参阅SimpleDTO 项目

  • 转换为数组: $listStats->toArray()
  • 转换为 JSON:json_encode($listStats);
  • 序列化(作为 JSON):serialize($listStats);

用例

PHPExperts\NeverBounceClient
✔ 可以构建自身
✔ 将验证有效电子邮件
✔ 将验证通配符电子邮件
✔ 将验证无效域名电子邮件
✔ 将验证无效账户电子邮件
✔ 将检测免费电子邮件托管服务
✔ 可以确定电子邮件是否有效
✔ 可以确定电子邮件是否有无效域名
✔ 可以确定电子邮件是否有无效账户

PHPExperts\NeverBounceClient: 批量验证
✔ 可以提交批量验证请求
✔ 可以轮询任务直到完成
✔ 将检索批量验证结果

测试

# Run without needing a NeverBounce key / not using up your free quota.
phpunit --testdox --exclude-group=thorough

# Run the full suite.
phpunit --testdox 

贡献者

Theodore R. Smith theodore@phpexperts.pro
GPG 指纹:4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
CEO:PHP Experts, Inc.

许可证

MIT 许可证。有关更多信息,请参阅许可证文件