PHP code example of knack / zerobounce

1. Go to this page and download the library: Download knack/zerobounce library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

knack / zerobounce example snippets




use Knack\ZeroBounce\API\ZeroBounce;
use Knack\ZeroBounce\Enums\StatusEnum;

class EmailService {
    /**
     * @var ZeroBounce
     */
    private $zeroBounce;

    /**
     * EmailService constructor.
     *
     * @param ZeroBounce $zeroBounce
     */
    public function __construct(ZeroBounce $zeroBounce) {
        $this->zeroBounce = $zeroBounce;
    }

    /**
     * Validates an email address from blacklists and verifies that that domain is real.
     *
     * @param string $emailAddress
     * @param string $ipAddress
     *
     * @return bool
     */
    public function isValid(string $emailAddress, string $ipAddress = ''): bool
    {
        $response = $this->zeroBounce->validate($emailAddress, $ipAddress);

        if($response->status === StatusEnum::VALID) {
            return true;
        }

        return false;
    }
}



use Knack\ZeroBounce\API\ZeroBounce;
use Knack\ZeroBounce\Enums\StatusEnum;

class EmailService {
    /**
     * @var ZeroBounce
     */
    private $zeroBounce;

    /**
     * EmailService constructor.
     */
    public function __construct() {
        $this->zeroBounce = new ZeroBounce(getenv('ZEROBOUNCE_API_KEY'));
    }

    /**
     * Validates an email address from blacklists and verifies that that domain is real.
     *
     * @param string $emailAddress
     * @param string $ipAddress
     *
     * @return bool
     */
    public function isValid(string $emailAddress, string $ipAddress = ''): bool
    {
        $response = $this->zeroBounce->validate($emailAddress, $ipAddress);

        if($response->status === StatusEnum::VALID) {
            return true;
        }

        return false;
    }
}