How to Partially Validate an Email Address in PHP
While fully validating an email address typically entails (silently) contacting the email server and waiting for a response, it isn’t always necessary to involve that many moving parts. You can partially validate email addresses by calling our Partial Email Validation API; the underlying service will simply identify if the address’ parent domain has email servers defined, and if so, it’ll return a string containing information about those servers.
To structure your API call in minutes, follow steps below to implement ready-to-run PHP code examples.
First, run this command to install the SDK:
composer require cloudmersive/cloudmersive_validate_api_client
Then, copy and paste the following code:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\EmailApi(
new GuzzleHttp\Client(),
$config
);
$email = "email_example"; // string | Email address to validate, e.g. \"support@cloudmersive.com\". The input is a string so be sure to enclose it in double-quotes.
try {
$result = $apiInstance->emailAddressGetServers($email);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling EmailApi->emailAddressGetServers: ', $e->getMessage(), PHP_EOL;
}
?>
You can authenticate up to 800 free API calls per month by registering a free account on our website. Creating a free account will provide you with a free-tier API key, which you can easily copy to your clipboard and paste into the $config line above.
After that, you’re good to go!