Block Trashmail Detect disposable email addresses and block them

PHP

curl

// Initiate curl instance
$curl = curl_init();

// Set variables
$endpoint = "https://api.block-trashmail.de";
$domain = "example.com";

// check for email address and only use domain
if (filter_var($domain, FILTER_VALIDATE_EMAIL)) {
    list($local, $domain) = explode("@", $domain);
}

// Set parameters
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_USERAGENT => "PHP curl",
    CURLOPT_URL => "{$endpoint}/check/{$domain}",
));

// Make request and save the result in a variable
$response = curl_exec($curl);

// Handle JSON
$response = json_decode($response);

// Check for errors
if (!$response->error) {
    // Evaluate response
    if ($response->results->listed) {
        echo "{$domain} is a trashmail.";
    } else {
        echo "{$domain} is NOT a trashmail.";
    }
} else {
    // Return error message
    echo "An error occurred: {$response->error->message}";
}

// Clear curl instance (free space)
curl_close($curl);

file_get_contents()

// Set variables
$endpoint = "https://api.block-trashmail.de";
$domain = "example.com";

// check for email address and only use domain
if (filter_var($domain, FILTER_VALIDATE_EMAIL)) {
    list($local, $domain) = explode("@", $domain);
}

// Set value for user_agent
$context = stream_context_create(array(
    "http" => array(
        "user_agent" => "PHP file_get_contents",
    )
));

// Make request and save the result in a variable
$response = file_get_contents("{$endpoint}/check/{$domain}", false, $context);

// Handle JSON
$response = json_decode($response);

// Check for errors
if (!$response->error) {
    // Evaluate response
    if ($response->results->listed) {
        echo "{$domain} is a trashmail.";
    } else {
        echo "{$domain} is NOT a trashmail.";
    }
} else {
    // Return error message
    echo "An error occurred: {$response->error->message}";
}