By Email Checker Team · 12 min read
Email Validation API: Complete Integration Guide
Learn how to integrate an email validation API into your application with code examples in JavaScript, Python, and PHP.
Table of Contents
An email validation API lets you verify email addresses programmatically within your application. Instead of manually checking addresses in a web interface, your code sends a request and receives a structured response. This is essential for real-time form validation, CRM integration, and automated list cleaning.
This guide walks you through integrating an email validation API using JavaScript, Python, and PHP. You will learn how to make requests, interpret responses, handle errors, and follow best practices for production use.
Why Use an Email Validation API
APIs offer several advantages over manual validation tools:
- Real-time validation: Validate emails at the moment of entry, before they reach your database
- Automation: Process thousands of addresses without manual intervention
- Structured data: Get machine-readable responses you can use in your application logic
- Scalability: APIs handle millions of requests without performance degradation
- Integration: Embed validation into signup forms, CRMs, and data pipelines
If you are building a website, consider using our embeddable validation widget instead. It provides the same real-time validation without writing any API code. For developers who need full control, the API is the right choice.
How the API Works
Our API follows a simple REST pattern. You send a GET or POST request to the validation endpoint with the email address, and receive a JSON response with the results.
API Endpoint:
GET https://api.emailvalidator.io/v1/validate?email=example@domain.com Required parameters:
email- The email address to validate
Authentication: Include your API key in the request header or as a query parameter.
Authorization: Bearer YOUR_API_KEY Full documentation is available at our API documentation page.
Understanding the Response
A typical API response includes the following fields:
{
"email": "user@example.com",
"valid": true,
"syntax_valid": true,
"domain_valid": true,
"mx_valid": true,
"smtp_valid": true,
"is_disposable": false,
"is_role_based": false,
"is_catch_all": false,
"suggestion": null,
"risk_level": "low"
} Key fields explained:
valid- Overall validity result (true/false)syntax_valid- Whether the email follows RFC formatdomain_valid- Whether the domain existsmx_valid- Whether the domain has MX recordssmtp_valid- Whether the mailbox exists (SMTP check)is_disposable- Whether this is a temporary/disposable emailis_role_based- Whether this is a generic address (info@, admin@)is_catch_all- Whether the domain accepts all addressesrisk_level- overall risk assessment (low, medium, high)
JavaScript Integration
Here is how to validate emails in a Node.js or browser JavaScript application:
Browser (Fetch API)
async function validateEmail(email) {
const response = await fetch(
`https://api.emailvalidator.io/v1/validate?email=${encodeURIComponent(email)}`,
{
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
}
);
const result = await response.json();
if (result.valid) {
console.log(`${email} is a valid email address`);
} else {
console.log(`${email} is invalid: ${result.suggestion || 'unknown reason'}`);
}
return result;
}
// Use in a form
document.getElementById('email-input').addEventListener('blur', (e) => {
validateEmail(e.target.value);
}); Node.js (Axios)
const axios = require('axios');
async function validateEmail(email) {
try {
const { data } = await axios.get(
'https://api.emailvalidator.io/v1/validate',
{
params: { email },
headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
}
);
return data;
} catch (error) {
console.error('Validation failed:', error.message);
return null;
}
}
validateEmail('user@example.com'); Form Validation Example
const form = document.getElementById('signup-form');
const emailInput = document.getElementById('email');
const errorDiv = document.getElementById('email-error');
let debounceTimer;
emailInput.addEventListener('input', (e) => {
clearTimeout(debounceTimer);
errorDiv.textContent = '';
debounceTimer = setTimeout(async () => {
const email = e.target.value.trim();
if (!email) return;
const result = await validateEmail(email);
if (!result.valid) {
errorDiv.textContent = result.suggestion
? `Did you mean ${result.suggestion}?`
: 'Please enter a valid email address';
errorDiv.style.color = 'red';
} else if (result.is_disposable) {
errorDiv.textContent = 'Please use a permanent email address';
errorDiv.style.color = 'orange';
} else {
errorDiv.textContent = 'Email looks good!';
errorDiv.style.color = 'green';
}
}, 500);
}); The 500ms debounce prevents excessive API calls while the user is still typing. This is important for staying within rate limits and keeping the experience smooth.
Python Integration
Python makes API integration straightforward with the requests library:
Basic Validation
import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.emailvalidator.io/v1"
def validate_email(email):
response = requests.get(
f"{BASE_URL}/validate",
params={"email": email},
headers={"Authorization": f"Bearer {API_KEY}"}
)
response.raise_for_status()
return response.json()
result = validate_email("user@example.com")
if result["valid"]:
print(f"{result['email']} is valid")
else:
print(f"{result['email']} is invalid") Bulk Validation
import requests
import csv
import time
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.emailvalidator.io/v1"
def validate_bulk(emails, batch_size=100):
results = []
for i in range(0, len(emails), batch_size):
batch = emails[i:i+batch_size]
response = requests.post(
f"{BASE_URL}/validate-batch",
json={"emails": batch},
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
)
results.extend(response.json()["results"])
time.sleep(1) # Rate limit respect
return results
# Read emails from CSV
with open("subscribers.csv") as f:
emails = [row["email"] for row in csv.DictReader(f)]
results = validate_bulk(emails)
valid = [r for r in results if r["valid"]]
invalid = [r for r in results if not r["valid"]]
print(f"Valid: {len(valid)}, Invalid: {len(invalid)}")
# Save cleaned list
with open("cleaned.csv", "w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=["email", "valid", "risk_level"])
writer.writeheader()
writer.writerows(valid) Django Form Integration
import requests
from django import forms
API_KEY = "YOUR_API_KEY"
class SignupForm(forms.Form):
email = forms.EmailField()
def clean_email(self):
email = self.cleaned_data["email"]
response = requests.get(
"https://api.emailvalidator.io/v1/validate",
params={"email": email},
headers={"Authorization": f"Bearer {API_KEY}"}
)
result = response.json()
if not result["valid"]:
raise forms.ValidationError(
result.get("suggestion") or "Please enter a valid email address."
)
if result["is_disposable"]:
raise forms.ValidationError(
"Please use a permanent email address."
)
return email PHP Integration
PHP integration works well with cURL or Guzzle:
cURL Example
<?php
function validateEmail($email) {
$apiKey = 'YOUR_API_KEY';
$url = "https://api.emailvalidator.io/v1/validate?email=" . urlencode($email);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer {$apiKey}"
]
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
$result = validateEmail('user@example.com');
if ($result['valid']) {
echo "{$result['email']} is valid
";
} else {
echo "{$result['email']} is invalid
";
if ($result['suggestion']) {
echo "Did you mean {$result['suggestion']}?
";
}
}
?> WordPress Plugin Integration
<?php
add_action('wp_ajax_validate_email', 'my_validate_email');
add_action('wp_ajax_nopriv_validate_email', 'my_validate_email');
function my_validate_email() {
$email = sanitize_email($_POST['email']);
$api_key = get_option('ev_api_key');
$response = wp_remote_get(
"https://api.emailvalidator.io/v1/validate",
[
'headers' => ['Authorization' => "Bearer {$api_key}"],
'body' => ['email' => $email]
]
);
$result = json_decode(wp_remote_retrieve_body($response), true);
wp_send_json($result);
}
// In your form template, add AJAX call to wp-admin/admin-ajax.php
// action=validate_email&email=user@example.com
?> API Best Practices
Follow these guidelines to get the most out of your API integration:
1. Debounce User Input
Never validate on every keystroke. Wait 300-500ms after the user stops typing. This reduces API calls and improves performance.
2. Cache Results
If you validate the same email multiple times (e.g., in a form with multiple submissions), cache the result for 24 hours. This saves API credits and improves response time.
3. Handle Errors Gracefully
API calls can fail due to network issues, rate limits, or service downtime. Always implement fallback behavior. If validation fails, let the user proceed but flag the email for manual review.
4. Validate at Multiple Points
Use real-time validation in forms (via the API or widget) and periodic bulk validation on your existing list (via bulk tool). These serve different purposes and complement each other.
5. Monitor Your API Usage
Track how many validations you perform daily. Set up alerts when you approach your plan limits. This prevents unexpected charges or service interruptions.
6. Do Not Block on Validation Failure
If your API is unreachable, do not prevent form submissions. Accept the email and validate it later in a background process. Blocking users because of a third-party API outage is a poor user experience.
When to Use the API vs. Other Tools
The API is the right choice when you need programmatic validation in your application. But it is not always the best option:
- Single email checks: Use the web validator
- Large list cleaning: Use the bulk validation tool
- No-code form validation: Use the embeddable widget
- Programmatic validation: Use the API
Many users combine these tools. For example, you might use the widget for real-time form validation, the API for custom integrations, and the bulk tool for quarterly list cleaning. Each serves its purpose.
Frequently Asked Questions
What programming languages can I use with the API?
Any language that can make HTTP requests. We provide examples and libraries for JavaScript, Python, PHP, Ruby, Java, Go, and C#. The API uses standard REST conventions, so integration is straightforward in any language.
How many API requests can I make per month?
This depends on your plan. The free tier includes 1,000 requests per month. Paid plans start at 10,000 requests per month. Check our pricing page for current limits.
Is the API fast enough for real-time form validation?
Yes. Average response time is under 1 second for single validations. With debouncing (waiting 300-500ms after the user stops typing), the validation happens in the background and does not block the user experience.
Can I validate emails in bulk via the API?
Yes. The batch endpoint accepts up to 1,000 emails per request. For larger lists, use the bulk validation tool which handles files up to 100,000 addresses.
How do I handle API errors in my application?
Implement a try-catch pattern. If the API returns an error or times out, log the error and allow the user to proceed. You can validate the email later in a background job. Never block form submissions because of API failures.
Is my data secure when using the API?
Yes. All API requests use HTTPS encryption. We do not store email addresses after validation. Your API key provides authentication, and we recommend rotating it periodically for security.