- StoreForge API: e-commerce site generator via WEVIA - LeadForge API: B2B lead generation + ICP + sequences - ProposalAI API: commercial proposal generator - BlueprintAI API: process/architecture document generator - MailWarm API: email warmup status/start/history - OutreachAI API: cold outreach sequences + subject lines - FormBuilder API: AI form generator - EmailVerify API: email validation (MX, disposable, format) - Auth OTP: replaces email-only auth with OTP/magic-link - SQL migration: auth_otp + auth_attempts tables - WEVIA proxy library: routes all AI calls through server-side Ollama - Auth library: API key validation + rate limiting via Redis Co-authored-by: Yacineutt <Yacineutt@users.noreply.github.com>
93 lines
2.7 KiB
PHP
93 lines
2.7 KiB
PHP
<?php
|
|
/**
|
|
* EmailVerify API — Email validation service
|
|
* GET /api/emailverify/check?email=test@example.com
|
|
*/
|
|
require_once __DIR__ . '/../lib/auth.php';
|
|
|
|
$user = requireAuth();
|
|
rateLimitCheck($user['id'], 100, 60);
|
|
|
|
$email = $_GET['email'] ?? '';
|
|
$input = json_decode(file_get_contents('php://input'), true);
|
|
if (empty($email) && isset($input['email'])) {
|
|
$email = $input['email'];
|
|
}
|
|
$bulk = $input['emails'] ?? [];
|
|
|
|
if (empty($email) && empty($bulk)) {
|
|
http_response_code(400);
|
|
echo json_encode(['error' => 'email ou emails[] requis']);
|
|
exit;
|
|
}
|
|
|
|
function verifyEmail($email) {
|
|
$result = [
|
|
'email' => $email,
|
|
'valid' => false,
|
|
'format_valid' => false,
|
|
'mx_found' => false,
|
|
'disposable' => false,
|
|
'role_account' => false,
|
|
'free_provider' => false,
|
|
'score' => 0
|
|
];
|
|
|
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$result['reason'] = 'Format invalide';
|
|
return $result;
|
|
}
|
|
$result['format_valid'] = true;
|
|
$result['score'] += 20;
|
|
|
|
$domain = explode('@', $email)[1];
|
|
|
|
if (getmxrr($domain, $mxhosts)) {
|
|
$result['mx_found'] = true;
|
|
$result['mx_records'] = $mxhosts;
|
|
$result['score'] += 30;
|
|
} else {
|
|
$result['reason'] = 'Pas de MX record';
|
|
return $result;
|
|
}
|
|
|
|
$disposable = ['tempmail.com', 'throwaway.email', 'guerrillamail.com', 'mailinator.com', 'yopmail.com'];
|
|
if (in_array($domain, $disposable)) {
|
|
$result['disposable'] = true;
|
|
$result['score'] -= 50;
|
|
$result['reason'] = 'Adresse jetable';
|
|
return $result;
|
|
}
|
|
$result['score'] += 20;
|
|
|
|
$freeProviders = ['gmail.com', 'yahoo.com', 'hotmail.com', 'outlook.com', 'protonmail.com'];
|
|
$result['free_provider'] = in_array($domain, $freeProviders);
|
|
|
|
$roleAccounts = ['admin', 'info', 'contact', 'support', 'sales', 'noreply', 'no-reply', 'postmaster', 'webmaster'];
|
|
$localPart = explode('@', $email)[0];
|
|
$result['role_account'] = in_array(strtolower($localPart), $roleAccounts);
|
|
if (!$result['role_account']) $result['score'] += 10;
|
|
|
|
if (checkdnsrr($domain, 'A') || checkdnsrr($domain, 'AAAA')) {
|
|
$result['score'] += 20;
|
|
}
|
|
|
|
$result['valid'] = $result['score'] >= 70;
|
|
$result['score'] = min(100, $result['score']);
|
|
|
|
return $result;
|
|
}
|
|
|
|
if (!empty($bulk)) {
|
|
$results = array_map('verifyEmail', array_slice($bulk, 0, 500));
|
|
$valid = count(array_filter($results, fn($r) => $r['valid']));
|
|
echo json_encode([
|
|
'total' => count($results),
|
|
'valid' => $valid,
|
|
'invalid' => count($results) - $valid,
|
|
'results' => $results
|
|
]);
|
|
} else {
|
|
echo json_encode(verifyEmail($email));
|
|
}
|