diff --git a/wp-multi-ticket.php b/wp-multi-ticket.php index 30ac2a8..dbf5f74 100644 --- a/wp-multi-ticket.php +++ b/wp-multi-ticket.php @@ -64,7 +64,29 @@ class WP_Multi_Ticket_Pro { } /** - * FIX: Verbesserte Konfiguration für PHPMailer mit Server-Check + * Hilfsfunktion: Letzte Fehlermeldung aus dem Log holen + */ + private function get_last_error_log_entry() { + $log_file = WP_CONTENT_DIR . '/debug.log'; + if ( ! file_exists( $log_file ) || ! is_readable( $log_file ) ) return null; + + // Letzte 5KB der Datei lesen + $lines = array_reverse( file( $log_file ) ); + foreach ( $lines as $line ) { + // Nach SMTP Debug Zeilen suchen + if ( strpos( $line, 'SMTP Debug' ) !== false ) { + return esc_html( trim( $line ) ); + } + // Nach PHP Fatal Warnings suchen + if ( strpos( $line, 'Fatal error' ) !== false ) { + return esc_html( trim( $line ) ); + } + } + return null; + } + + /** + * FIX: Verbesserte Konfiguration für PHPMailer */ public function configure_phpmailer( $phpmailer ) { $smtp_enabled = get_option( 'wmt_smtp_enabled' ); @@ -72,18 +94,27 @@ class WP_Multi_Ticket_Pro { if ( $smtp_enabled == '1' || $smtp_enabled === true ) { $encryption = get_option( 'wmt_smtp_encryption', '' ); - // Prüfen, ob OpenSSL geladen ist, wenn Verschlüsselung gefordert ist + // Prüfen, ob OpenSSL geladen ist if ( ( $encryption === 'tls' || $encryption === 'ssl' ) && ! extension_loaded('openssl') ) { - // Wir können hier keine Notices werfen, also loggen wir es - error_log('WMT SMTP Error: OpenSSL extension is missing, but encryption is set to ' . $encryption); - return; // Abbrechen, sonst crasht es + error_log('WMT SMTP Error: OpenSSL extension missing.'); + // Setzen einer Error-Info, die manuell abgerufen werden kann + global $wmt_last_smtp_error; + $wmt_last_smtp_error = "FATAL: PHP OpenSSL Extension fehlt. Bitte kontaktieren Sie Ihren Webhoster."; + return; } $phpmailer->isSMTP(); $phpmailer->Host = get_option( 'wmt_smtp_host', 'localhost' ); $phpmailer->Port = get_option( 'wmt_smtp_port', 25 ); - $phpmailer->SMTPSecure = ( $encryption === 'tls' ) ? 'tls' : ( ( $encryption === 'ssl' ) ? 'ssl' : '' ); + // SSL/TLS korrekt setzen + if ( $encryption === 'tls' ) { + $phpmailer->SMTPSecure = 'tls'; + } elseif ( $encryption === 'ssl' ) { + $phpmailer->SMTPSecure = 'ssl'; + } else { + $phpmailer->SMTPSecure = ''; + } $smtp_auth = get_option( 'wmt_smtp_auth' ); $phpmailer->SMTPAuth = ( $smtp_auth == '1' || $smtp_auth === true ); @@ -92,14 +123,14 @@ class WP_Multi_Ticket_Pro { $phpmailer->Username = get_option( 'wmt_smtp_username', '' ); $phpmailer->Password = get_option( 'wmt_smtp_password', '' ); - // WICHTIG: Envelope Sender setzen (behebt "Sender address rejected") + // WICHTIG: Envelope Sender setzen $phpmailer->Sender = $phpmailer->Username; } if ( get_option( 'wmt_smtp_debug', false ) ) { - $phpmailer->SMTPDebug = 3; + $phpmailer->SMTPDebug = 3; // Client + Server $phpmailer->Debugoutput = function($str, $level) { - error_log("SMTP Debug [Lvl $level]: $str"); + error_log("WMT SMTP: $str"); }; } } @@ -171,18 +202,29 @@ class WP_Multi_Ticket_Pro { $result = wp_mail( $to, $subject, $html_message, $headers, $attachments ); + // Logging für Debugging if ( get_option( 'wmt_mail_logging', true ) ) { - $log_entry = array( + $error_msg = 'Mail delivery failed'; + + // Wenn es fehlschlägt, versuchen wir den letzten Fehler aus dem Log zu holen für mehr Details + if ( ! $result ) { + $log_entry = $this->get_last_error_log_entry(); + if ( $log_entry ) { + $error_msg .= " (Server Log: " . $log_entry . ")"; + } + } + + $logs = get_option( 'wmt_mail_logs', array() ); + array_unshift( $logs, array( 'timestamp' => current_time( 'mysql' ), 'to' => $to, 'subject' => $subject, 'success' => $result ? 'YES' : 'NO', - 'error' => $result ? '' : 'Mail delivery failed (check SMTP settings or Spam folder)' - ); + 'error' => $result ? '' : $error_msg + )); - $logs = get_option( 'wmt_mail_logs', array() ); - array_unshift( $logs, $log_entry ); - $logs = array_slice( $logs, 0, 50 ); + // Nur letzte 50 behalten + $logs = array_slice( $logs, 0, 50 ); update_option( 'wmt_mail_logs', $logs ); } @@ -473,33 +515,43 @@ class WP_Multi_Ticket_Pro { } public function render_mail_settings_page() { - // Server-Diagnose Notice - if ( get_option('wmt_smtp_enabled') && in_array(get_option('wmt_smtp_encryption'), array('ssl', 'tls')) ) { - if ( ! extension_loaded('openssl') ) { - echo '
Kritischer Fehler: Ihre PHP-Installation hat die openssl Erweiterung nicht geladen. SMTP mit SSL/TLS kann nicht funktionieren. Bitte wenden Sie sich an Ihren Hoster.