HEX
Server: Apache
System: Linux info 3.0 #1337 SMP Tue Jan 01 00:00:00 CEST 2000 all GNU/Linux
User: u115237990 (7145895)
PHP: 8.3.32
Disabled: NONE
Upload Files
File: /homepages/35/d993672390/htdocs/dermiteseborrheique/admin/test-email.php
<?php
define('DS_APP', true);
require_once dirname(__DIR__) . '/includes/init.php';

$user = auth_require();
if (!$user['is_admin']) redirect('app/dashboard.php');

$message = '';
$success = false;

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    csrf_verify();
    $type = post('type');
    $to   = sanitize_string(post('to'), 100) ?: $user['email'];

    switch ($type) {
        case 'welcome':
            $success = mail_send_welcome($to, $user['name']);
            break;
        case 'reminder':
            $success = mail_send_journal_reminder($to, $user['name'], 2);
            break;
        case 'suspect':
            $success = mail_send_new_suspect($to, $user['name'], [
                ['name' => 'Sodium Laureth Sulfate', 'score' => 78],
                ['name' => 'Parfum', 'score' => 65],
            ]);
            break;
        case 'weekly':
            $success = mail_send_weekly_summary($to, $user['name'], [
                'entries' => 5, 'crises' => 2, 'avg_score' => 6.2
            ], ['name' => 'Tomates', 'score' => 72]);
            break;
    }
    // Debug : tester curl directement
    $debugInfo = '';
    if (!$success) {
        $ch = curl_init('https://api.brevo.com/v3/smtp/email');
        curl_setopt_array($ch, [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST           => true,
            CURLOPT_POSTFIELDS     => json_encode([
                'sender'      => ['name'=>'Test','email'=>'contact@dermiteseborrheique.fr'],
                'to'          => [['email'=>$to,'name'=>'Test']],
                'subject'     => 'Test',
                'htmlContent' => '<p>Test</p>',
                'textContent' => 'Test',
            ]),
            CURLOPT_HTTPHEADER => [
                'Accept: application/json',
                'Content-Type: application/json',
                'api-key: ' . MAIL_PASSWORD,
            ],
            CURLOPT_TIMEOUT => 15,
        ]);
        $resp     = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $curlErr  = curl_error($ch);
        curl_close($ch);
        $debugInfo = " | HTTP:{$httpCode} | curl:{$curlErr} | resp:" . substr($resp, 0, 200);
    }
    $message = $success ? "✅ Email envoyé à {$to}" : "❌ Échec{$debugInfo}";
}

$pageTitle  = 'Test emails';
$activePage = 'admin';
ob_start();
?>
<div style="max-width:500px;">
  <div style="font-size:1rem;font-weight:800;margin-bottom:20px;">🧪 Test des emails transactionnels</div>

  <?php if ($message): ?>
    <div style="padding:12px 16px;border-radius:8px;margin-bottom:16px;
                background:<?= $success?'rgba(0,232,122,0.1)':'rgba(255,107,138,0.1)' ?>;
                border:1px solid <?= $success?'rgba(0,232,122,0.2)':'rgba(255,107,138,0.2)' ?>;
                color:<?= $success?'var(--emerald)':'var(--rose)' ?>;">
      <?= e($message) ?>
    </div>
  <?php endif; ?>

  <form method="POST" style="background:var(--surface);border:1px solid var(--border);border-radius:12px;padding:20px;">
    <?= csrf_field() ?>

    <div style="margin-bottom:16px;">
      <label style="font-size:0.8rem;font-weight:600;color:var(--text-dim);display:block;margin-bottom:6px;">
        Email destinataire
      </label>
      <input type="email" name="to" value="<?= e($user['email']) ?>"
             style="width:100%;background:var(--surface2);border:1px solid var(--border);border-radius:8px;padding:9px 12px;color:var(--text);font-size:0.85rem;font-family:inherit;">
    </div>

    <div style="margin-bottom:20px;">
      <label style="font-size:0.8rem;font-weight:600;color:var(--text-dim);display:block;margin-bottom:6px;">
        Type d'email
      </label>
      <select name="type" style="width:100%;background:var(--surface2);border:1px solid var(--border);border-radius:8px;padding:9px 12px;color:var(--text);font-size:0.85rem;font-family:inherit;">
        <option value="welcome">🎉 Bienvenue</option>
        <option value="reminder">📔 Rappel journal</option>
        <option value="suspect">⚠️ Alerte suspects</option>
        <option value="weekly">📊 Résumé hebdo</option>
      </select>
    </div>

    <button type="submit" style="background:var(--cyan);color:var(--bg);border:none;border-radius:8px;padding:10px 20px;font-size:0.85rem;font-weight:700;cursor:pointer;font-family:inherit;width:100%;">
      📨 Envoyer le test
    </button>
  </form>
</div>
<?php
$content = ob_get_clean();
require DS_VIEWS . 'layouts/app.php';