wp-multi-ticket.php aktualisiert
This commit is contained in:
@@ -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,17 +202,28 @@ 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 );
|
||||
// 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 '<div class="notice notice-error is-dismissible"><p><strong>Kritischer Fehler:</strong> Ihre PHP-Installation hat die <code>openssl</code> Erweiterung nicht geladen. SMTP mit SSL/TLS kann nicht funktionieren. Bitte wenden Sie sich an Ihren Hoster.</p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Test-Mail senden
|
||||
if ( isset( $_POST['wmt_send_test_mail'] ) && check_admin_referer( 'wmt_test_mail' ) ) {
|
||||
$test_email = sanitize_email( $_POST['test_email'] );
|
||||
$result = $this->send_mail(
|
||||
$test_email,
|
||||
'Test E-Mail von WP Multi Ticket Pro',
|
||||
'Wenn Sie diese E-Mail erhalten, funktioniert der E-Mail-Versand korrekt!'
|
||||
);
|
||||
|
||||
if ( $result ) {
|
||||
echo '<div class="wmt-alert">✓ Test-E-Mail erfolgreich an ' . esc_html($test_email) . ' gesendet!</div>';
|
||||
if ( isset( $_POST['wmt_send_test_mail'] ) ) {
|
||||
// Prüfen des Nonce
|
||||
$nonce_value = isset( $_POST['wmt_test_nonce'] ) ? $_POST['wmt_test_nonce'] : '';
|
||||
if ( ! wp_verify_nonce( $nonce_value, 'wmt_test_mail' ) ) {
|
||||
echo '<div class="wmt-error">Sicherheitsfehler beim Senden der Test-E-Mail.</div>';
|
||||
} else {
|
||||
echo '<div class="wmt-error">✗ Test-E-Mail konnte nicht gesendet werden. Bitte prüfen Sie die Einstellungen und Logs.</div>';
|
||||
$test_email = sanitize_email( $_POST['test_email'] );
|
||||
|
||||
// Debug-Modus temporär für Test aktivieren
|
||||
$orig_debug = get_option('wmt_smtp_debug', false);
|
||||
if(!$orig_debug) update_option('wmt_smtp_debug', '1');
|
||||
|
||||
$result = $this->send_mail(
|
||||
$test_email,
|
||||
'Test E-Mail von WP Multi Ticket Pro',
|
||||
'Wenn Sie diese E-Mail erhalten, funktioniert der E-Mail-Versand korrekt!'
|
||||
);
|
||||
|
||||
// Debug-Modus zurücksetzen
|
||||
update_option('wmt_smtp_debug', $orig_debug);
|
||||
|
||||
if ( $result ) {
|
||||
echo '<div class="wmt-alert">✓ Test-E-Mail erfolgreich an ' . esc_html($test_email) . ' gesendet!</div>';
|
||||
} else {
|
||||
echo '<div class="wmt-error">✗ Test-E-Mail konnte nicht gesendet werden. Prüfen Sie die Tabelle unten für Details.</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Logs löschen
|
||||
if ( isset( $_POST['wmt_clear_logs'] ) && check_admin_referer( 'wmt_clear_logs' ) ) {
|
||||
delete_option( 'wmt_mail_logs' );
|
||||
echo '<div class="wmt-alert">Mail-Logs gelöscht.</div>';
|
||||
if ( isset( $_POST['wmt_clear_logs'] ) ) {
|
||||
// Manuelle Nonce-Prüfung da settings_fields hier nicht verwendet wird
|
||||
if ( check_admin_referer( 'wmt_clear_logs' ) ) {
|
||||
delete_option( 'wmt_mail_logs' );
|
||||
echo '<div class="wmt-alert">Mail-Logs gelöscht.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
$logs = get_option( 'wmt_mail_logs', array() );
|
||||
@@ -509,8 +561,7 @@ class WP_Multi_Ticket_Pro {
|
||||
<h1>E-Mail Einstellungen</h1>
|
||||
|
||||
<div class="wmt-warning">
|
||||
<strong>⚠️ Wichtig:</strong> WordPress verwendet standardmäßig die PHP mail() Funktion, die oft nicht zuverlässig funktioniert.
|
||||
Für produktive Systeme empfehlen wir SMTP zu aktivieren.
|
||||
<strong>⚠️ Wichtig:</strong> Wenn SMTP nicht funktioniert, prüfen Sie unten die Logs für den genauen Fehler.
|
||||
</div>
|
||||
|
||||
<form method="post" action="options.php">
|
||||
@@ -616,9 +667,9 @@ class WP_Multi_Ticket_Pro {
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="wmt_smtp_debug" value="1" <?php checked( get_option('wmt_smtp_debug'), 1 ); ?>>
|
||||
SMTP Debug aktivieren (schreibt in PHP error_log)
|
||||
SMTP Debug aktivieren (schreibt Logs für jeden Versand)
|
||||
</label>
|
||||
<p class="description">Nur für Fehlersuche aktivieren!</p>
|
||||
<p class="description">Wichtig für den Test! Wird nach dem Test automatisch wieder ausgeschaltet.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -630,7 +681,7 @@ class WP_Multi_Ticket_Pro {
|
||||
|
||||
<h2>Test-E-Mail senden</h2>
|
||||
<form method="post">
|
||||
<?php wp_nonce_field( 'wmt_test_mail' ); ?>
|
||||
<input type="hidden" id="wmt_test_nonce" name="wmt_test_nonce" value="<?php echo wp_create_nonce('wmt_test_mail'); ?>" />
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th>Test-E-Mail an</th>
|
||||
@@ -646,8 +697,9 @@ class WP_Multi_Ticket_Pro {
|
||||
<hr>
|
||||
<h2>E-Mail Logs (letzte 50)</h2>
|
||||
<form method="post">
|
||||
<input type="hidden" name="wmt_clear_logs" value="1" />
|
||||
<?php wp_nonce_field( 'wmt_clear_logs' ); ?>
|
||||
<button type="submit" name="wmt_clear_logs" class="button">Logs löschen</button>
|
||||
<button type="submit" name="submit" class="button">Logs löschen</button>
|
||||
</form>
|
||||
<table class="wmt-mail-log-table">
|
||||
<thead>
|
||||
@@ -667,7 +719,10 @@ class WP_Multi_Ticket_Pro {
|
||||
<td class="<?php echo $log['success'] === 'YES' ? 'wmt-mail-success' : 'wmt-mail-failed'; ?>">
|
||||
<?php echo $log['success'] === 'YES' ? '✓ Gesendet' : '✗ Fehler'; ?>
|
||||
<?php if ( ! empty( $log['error'] ) ): ?>
|
||||
<br><small><?php echo esc_html( $log['error'] ); ?></small>
|
||||
<div style="font-size: 11px; margin-top: 5px; color: #d63638; word-break: break-all; background: #f9f9f9; padding: 5px; border: 1px solid #eee; max-width: 500px;">
|
||||
<strong>Server-Fehler:</strong><br>
|
||||
<?php echo esc_html( $log['error'] ); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -681,9 +736,9 @@ class WP_Multi_Ticket_Pro {
|
||||
<div style="background: #f9f9f9; padding: 20px; border-left: 4px solid #0073aa; margin-top: 20px;">
|
||||
<h3>E-Mails kommen nicht an?</h3>
|
||||
<ol>
|
||||
<li><strong>Logs prüfen:</strong> Aktivieren Sie Debug-Modus und schauen Sie in <code>wp-content/debug.log</code>.</li>
|
||||
<li><strong>Prüfen Sie das Log:</strong> Wenn die Test-Mail fehlschlägt, steht der genaue Fehler oben in der Tabelle unter "Server-Fehler".</li>
|
||||
<li><strong>Gmail Nutzer:</strong> Verwenden Sie ein <strong>App-Passwort</strong>, nicht Ihr normales Passwort. Port 587 + TLS.</li>
|
||||
<li><strong>OpenSSL Fehler:</strong> Wenn im Log steht "openssl extension missing", kontaktieren Sie Ihren Hoster.</li>
|
||||
<li><strong>OpenSSL Fehler:</strong> Wenn im Log steht "OpenSSL extension missing", kontaktieren Sie Ihren Hoster.</li>
|
||||
<li><strong>Firewall:</strong> Manche Hoster blockieren Port 25 und 587.</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user