diff --git a/api/wevia-test-email-intent.php b/api/wevia-test-email-intent.php index e12d98294..7b8a79976 100644 --- a/api/wevia-test-email-intent.php +++ b/api/wevia-test-email-intent.php @@ -1,105 +1,65 @@ 'test_email_send', 'tool' => 'draft_only_no_auto_send']; + $out['doctrine'] = 'JAMAIS envoi auto · Yacine seul clique Send'; - $out = ['intent' => 'test_email_send', 'tool' => 'pmta_test_internal']; - - // WHITELIST STRICTE — jamais autre destinataire - $allowed_recipients = [ - 'yacineutt@gmail.com', - 'ymahboub@weval-consulting.com', + // Whitelist interne pour tests + $whitelist = [ + 'yacineutt@gmail.com' => 'Yacine personal', + 'ymahboub@weval-consulting.com' => 'Yacine pro', ]; + // Fetch live stats + $stats = @file_get_contents("/var/www/html/api/ethica-latest.json"); + $sj = @json_decode($stats, true); + $total = number_format($sj['total'] ?? 0); + $emails = number_format($sj['with_email'] ?? 0); + $ts = date('Y-m-d H:i:s'); - $timestamp_compact = date('HMS'); + $subject = "[WEVAL TEST] Pipeline email check - " . date('H:i'); + $body = "Test pipeline interne WEVIA Master\n\n" + . "Timestamp: {$ts}\n" + . "Stats live:\n" + . "- Ethica HCPs: {$total}\n" + . "- Emails valides: {$emails}\n" + . "- Route: PMTA S95 port 25\n" + . "- Rate limit: 100/h\n\n" + . "Pipeline OK si tu recois ce mail apres clic Send.\n\n" + . "Dashboards:\n" + . "- /automation-hub.html\n" + . "- /partners-emails.html\n" + . "- /blade-actions.html"; - // Fetch stats live pour inclure dans le body - $stats = @file_get_contents('http://127.0.0.1/api/ethica-latest.json'); - $stats_json = @json_decode($stats, true); - $ethica_total = $stats_json['total'] ?? '?'; - $ethica_emails = $stats_json['with_email'] ?? '?'; - - $sent_log = []; - $errors = []; - - foreach ($allowed_recipients as $to) { - $subject = "[WEVAL AUTO-TEST {$timestamp_compact}] WEVIA intent test_email_send"; - $html = "
" - . "Envoyé automatiquement par WEVIA Master intent test_email_send
Timestamp: {$ts}
" - . "Ce mail confirme que le pipeline email interne fonctionne. Aucun client reel contacté.
" - . "Automation Hub · " - . "Partners Drafts
" - . ""; - - $ch = curl_init('http://127.0.0.1/api/wevads-v2-engine.php?action=send_test&token=WEVADS2026'); - curl_setopt_array($ch, [ - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => http_build_query([ - 'to' => $to, - 'subject' => $subject, - 'html' => $html, - 'method' => 'pmta', - 'from_name' => 'WEVAL Auto-Test', - 'from' => 'test@weval-consulting.com', - ]), - CURLOPT_RETURNTRANSFER => true, - CURLOPT_TIMEOUT => 15, - ]); - $r = curl_exec($ch); - $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); - - $result = @json_decode($r, true); - if ($result && ($result['sent'] ?? false) === true) { - $sent_log[] = [ - 'to' => $to, - 'status' => 'sent', - 'tracking_id' => $result['tracking_id'] ?? '', - 'smtp_response' => $result['detail']['response'] ?? '', - 'method' => $result['method'] ?? 'pmta', - ]; - } else { - $errors[] = ['to' => $to, 'error' => $result['error'] ?? 'unknown', 'raw' => substr($r, 0, 200)]; - } + $drafts = []; + foreach ($whitelist as $to => $label) { + $url = "https://mail.google.com/mail/u/0/?view=cm&fs=1&tf=cm&to=" . urlencode($to); + $url .= "&su=" . urlencode($subject); + $url .= "&body=" . urlencode($body); + $drafts[] = [ + 'to' => $to, + 'label' => $label, + 'subject' => $subject, + 'gmail_url' => $url, + 'action' => 'Yacine clique + Send (pas d\'envoi auto)', + ]; } - // Store trace - $trace_file = '/var/www/html/api/test-email-trace.json'; - $trace = [ - 'last_test_at' => $ts, - 'sent' => $sent_log, - 'errors' => $errors, - 'whitelist_enforced' => $allowed_recipients, - 'doctrine' => '64-ZERO-MANUAL + safe-test-whitelist', - ]; - @file_put_contents($trace_file, json_encode($trace, JSON_PRETTY_PRINT)); + // Trace + $trace = ['generated_at' => $ts, 'drafts' => $drafts, 'note' => 'DRAFTS ONLY · no auto-send']; + @file_put_contents('/var/www/html/api/test-email-drafts.json', json_encode($trace, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); - $out['sent'] = $sent_log; - $out['errors'] = $errors; - $out['whitelist'] = $allowed_recipients; - $out['total_sent'] = count($sent_log); - $out['total_errors'] = count($errors); - $out['trace_url'] = 'https://weval-consulting.com/api/test-email-trace.json'; - $out['summary'] = count($errors) === 0 - ? count($sent_log) . " emails envoyes avec succes via PMTA S95 (whitelist yacineutt + ymahboub)" - : count($sent_log) . " OK, " . count($errors) . " erreurs"; + $out['drafts'] = $drafts; + $out['count'] = count($drafts); + $out['dashboard'] = 'https://weval-consulting.com/test-email-drafts.html'; + $out['next_step'] = 'Ouvre les 2 gmail_url, clic Send pour chacun - tu verifies que le pipeline PMTA fonctionne'; header("Content-Type: application/json"); echo json_encode($out, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);