53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* SMTP-Verbindungstest — prüft Host, STARTTLS und Login aus config/config.php,
|
||
|
|
* OHNE eine E-Mail zu versenden (nur Verbindung + Auth, danach QUIT).
|
||
|
|
*
|
||
|
|
* NUR CLI — nie im Request-Pfad. Debug-Ausgabe bleibt aus, damit keine
|
||
|
|
* Zugangsdaten (Base64 im AUTH-Dialog) im Terminal oder in Logs landen.
|
||
|
|
*
|
||
|
|
* Aufruf: php bin/smtp-test.php
|
||
|
|
*/
|
||
|
|
if (PHP_SAPI !== 'cli') {
|
||
|
|
exit(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
require dirname(__DIR__) . '/app/bootstrap.php';
|
||
|
|
|
||
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
||
|
|
|
||
|
|
$smtp = config('smtp');
|
||
|
|
|
||
|
|
if (in_array($smtp['password'] ?? '', ['', 'POSTFACH_PASSWORT', 'BREVO_SMTP_KEY', 'CHANGE_ME'], true)) {
|
||
|
|
fwrite(STDERR, "Abbruch: In config/config.php steht noch kein echtes SMTP-Passwort.\n");
|
||
|
|
exit(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
echo "Teste {$smtp['host']}:{$smtp['port']} (STARTTLS) als {$smtp['username']} …\n";
|
||
|
|
|
||
|
|
$mail = new PHPMailer(true);
|
||
|
|
$mail->isSMTP();
|
||
|
|
$mail->Host = $smtp['host'];
|
||
|
|
$mail->Port = (int) $smtp['port'];
|
||
|
|
$mail->SMTPAuth = true;
|
||
|
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||
|
|
$mail->Username = $smtp['username'];
|
||
|
|
$mail->Password = $smtp['password'];
|
||
|
|
$mail->Timeout = 15;
|
||
|
|
|
||
|
|
try {
|
||
|
|
if ($mail->smtpConnect()) {
|
||
|
|
$mail->smtpClose();
|
||
|
|
echo "OK: Verbindung, STARTTLS und Login erfolgreich — keine Mail versendet.\n";
|
||
|
|
exit(0);
|
||
|
|
}
|
||
|
|
fwrite(STDERR, 'Fehler: ' . ($mail->ErrorInfo !== '' ? $mail->ErrorInfo : 'Verbindung fehlgeschlagen.') . "\n");
|
||
|
|
exit(1);
|
||
|
|
} catch (Throwable $e) {
|
||
|
|
fwrite(STDERR, 'Fehler: ' . $e->getMessage() . "\n");
|
||
|
|
exit(1);
|
||
|
|
}
|