"ok", "service" => "WEVIA LIFE Email", "capabilities" => ["send", "read", "list_boxes"]]); break; case "list_boxes": echo json_encode(["boxes" => [ ["email" => "ymahboub@weval-consulting.com", "type" => "cPanel/IMAP", "status" => "active"], ["email" => "yacineutt@gmail.com", "type" => "Gmail/SMTP", "status" => "configured"], ["email" => "contact@weval-consulting.com", "type" => "cPanel/IMAP", "status" => "active"], ]]); break; case "send": $to = $input["to"] ?? ""; $subject = $input["subject"] ?? "Message WEVIA"; $body = $input["body"] ?? ""; $from = $input["from"] ?? "ymahboub@weval-consulting.com"; if (empty($to) || empty($body)) { echo json_encode(["error" => "to and body required"]); exit; } // Use PHP mail() with custom headers $headers = "From: WEVIA <$from>\r\n"; $headers .= "Reply-To: $from\r\n"; $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; $headers .= "X-Mailer: WEVIA-LIFE/2.0\r\n"; $htmlBody = ""; $htmlBody .= nl2br(htmlspecialchars($body)); $htmlBody .= "

Envoyé via WEVIA LIFE — weval-consulting.com"; $htmlBody .= ""; $sent = mail($to, $subject, $htmlBody, $headers); echo json_encode(["status" => $sent ? "sent" : "failed", "to" => $to, "subject" => $subject]); break; case "read": // Proxy to WEVIA LIFE IMAP $ch = curl_init("http://127.0.0.1/api/wevialife-api.php?action=list&limit=" . ($input["limit"] ?? 5)); curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10]); $r = curl_exec($ch); curl_close($ch); echo $r ?: json_encode(["error" => "IMAP proxy failed"]); break; }