diff --git a/wp-multi-ticket.php b/wp-multi-ticket.php index 53427f3..30ac2a8 100644 --- a/wp-multi-ticket.php +++ b/wp-multi-ticket.php @@ -3,7 +3,7 @@ * Plugin Name: WP Multi Ticket Pro * Plugin URI: https://git.viper.ipv64.net/M_Viper/wp-multi-ticket * Description: Leistungsstarkes Ticket- und Support-System für WordPress mit Gast-Tickets, Admin-Antworten, CSV-Export, Dashboard-Widgets und integriertem Update-Management über Gitea. - * Version: 1.2 + * Version: 1.3 * Author: M_Viper * Author URI: https://m-viper.de * Requires at least: 6.7.2 @@ -17,8 +17,6 @@ * Support: https://t.me/M_Viper04 */ - - if ( ! defined( 'ABSPATH' ) ) exit; class WP_Multi_Ticket_Pro { @@ -47,6 +45,11 @@ class WP_Multi_Ticket_Pro { // Hook für Update-Benachrichtigung add_action( 'admin_notices', array( $this, 'check_plugin_updates' ) ); + // E-Mail-Konfiguration + add_action( 'phpmailer_init', array( $this, 'configure_phpmailer' ) ); + add_filter( 'wp_mail_from', array( $this, 'custom_wp_mail_from' ) ); + add_filter( 'wp_mail_from_name', array( $this, 'custom_wp_mail_from_name' ) ); + add_shortcode( 'wmt_form', array( $this, 'render_creation_form' ) ); add_shortcode( 'wmt_view', array( $this, 'render_ticket_view' ) ); add_shortcode( 'wmt_lookup', array( $this, 'render_lookup_form' ) ); @@ -60,7 +63,137 @@ class WP_Multi_Ticket_Pro { add_action( 'admin_init', array( $this, 'handle_csv_export' ) ); } - /** + /** + * FIX: Verbesserte Konfiguration für PHPMailer mit Server-Check + */ + public function configure_phpmailer( $phpmailer ) { + $smtp_enabled = get_option( 'wmt_smtp_enabled' ); + + if ( $smtp_enabled == '1' || $smtp_enabled === true ) { + $encryption = get_option( 'wmt_smtp_encryption', '' ); + + // Prüfen, ob OpenSSL geladen ist, wenn Verschlüsselung gefordert 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 + } + + $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' : '' ); + + $smtp_auth = get_option( 'wmt_smtp_auth' ); + $phpmailer->SMTPAuth = ( $smtp_auth == '1' || $smtp_auth === true ); + + if ( $phpmailer->SMTPAuth ) { + $phpmailer->Username = get_option( 'wmt_smtp_username', '' ); + $phpmailer->Password = get_option( 'wmt_smtp_password', '' ); + + // WICHTIG: Envelope Sender setzen (behebt "Sender address rejected") + $phpmailer->Sender = $phpmailer->Username; + } + + if ( get_option( 'wmt_smtp_debug', false ) ) { + $phpmailer->SMTPDebug = 3; + $phpmailer->Debugoutput = function($str, $level) { + error_log("SMTP Debug [Lvl $level]: $str"); + }; + } + } + + $phpmailer->CharSet = 'UTF-8'; + } + + /** + * Setzt die Absender-E-Mail + */ + public function custom_wp_mail_from( $original_email_address ) { + $custom_email = get_option( 'wmt_from_email', '' ); + return $custom_email ? $custom_email : $original_email_address; + } + + /** + * Setzt den Absender-Namen + */ + public function custom_wp_mail_from_name( $original_email_from ) { + $custom_name = get_option( 'wmt_from_name', '' ); + return $custom_name ? $custom_name : $original_email_from; + } + + /** + * Verbesserte E-Mail-Versand-Funktion mit Logging + */ + private function send_mail( $to, $subject, $message, $attachments = array() ) { + $html_message = ' + + + + + + + + +
+
+

' . get_bloginfo('name') . ' Support

+
+
+ ' . wpautop( $message ) . ' +
+ +
+ + '; + + $headers = array( + 'Content-Type: text/html; charset=UTF-8', + ); + + if ( get_option( 'wmt_bcc_admin', false ) ) { + $admin_email = get_option( 'wmt_admin_email', get_option('admin_email') ); + $headers[] = 'Bcc: ' . $admin_email; + } + + $result = wp_mail( $to, $subject, $html_message, $headers, $attachments ); + + if ( get_option( 'wmt_mail_logging', true ) ) { + $log_entry = array( + 'timestamp' => current_time( 'mysql' ), + 'to' => $to, + 'subject' => $subject, + 'success' => $result ? 'YES' : 'NO', + 'error' => $result ? '' : 'Mail delivery failed (check SMTP settings or Spam folder)' + ); + + $logs = get_option( 'wmt_mail_logs', array() ); + array_unshift( $logs, $log_entry ); + $logs = array_slice( $logs, 0, 50 ); + update_option( 'wmt_mail_logs', $logs ); + } + + if ( ! $result ) { + error_log( 'WMT Mail Error: Failed to send email to ' . $to . ' - Subject: ' . $subject ); + } + + return $result; + } + + /** * Prüft auf Updates von der Git-URL und zeigt eine Admin-Notice an */ public function check_plugin_updates() { @@ -149,9 +282,7 @@ class WP_Multi_Ticket_Pro { } - // *** HIER: korrigierter Hook-Name für die Analytics-Unterseite *** public function load_analytics_scripts( $hook ) { - // Für Submenu: parent slug wmt_tickets -> Hook: wmt-tickets_page_wmt_analytics if ( 'wmt-tickets_page_wmt_analytics' !== $hook ) return; $local_js = plugin_dir_path( __FILE__ ) . 'chart.js'; @@ -163,14 +294,12 @@ class WP_Multi_Ticket_Pro { } public function enqueue_styles() { - // Hier wird die eingestellte Schriftfarbe geholt (Standard: #6b7280 = rgb(107, 114, 128)) $custom_font_color = get_option( 'wmt_font_color', '#6b7280' ); ?>

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.

'; + } + } + + // 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 '
✓ Test-E-Mail erfolgreich an ' . esc_html($test_email) . ' gesendet!
'; + } else { + echo '
✗ Test-E-Mail konnte nicht gesendet werden. Bitte prüfen Sie die Einstellungen und Logs.
'; + } + } + + // Logs löschen + if ( isset( $_POST['wmt_clear_logs'] ) && check_admin_referer( 'wmt_clear_logs' ) ) { + delete_option( 'wmt_mail_logs' ); + echo '
Mail-Logs gelöscht.
'; + } + + $logs = get_option( 'wmt_mail_logs', array() ); + + ?> +
+

E-Mail Einstellungen

+ +
+ ⚠️ Wichtig: WordPress verwendet standardmäßig die PHP mail() Funktion, die oft nicht zuverlässig funktioniert. + Für produktive Systeme empfehlen wir SMTP zu aktivieren. +
+ +
+ + +

Grundeinstellungen

+ + + + + + + + + + + + + + + + + +
Absender E-Mail + +

Die E-Mail-Adresse, von der Tickets versendet werden.

+
Absender Name + +

Der Name, der als Absender angezeigt wird.

+
BCC an Admin + +
E-Mail Logging + +
+ +

SMTP Einstellungen (empfohlen)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SMTP aktivieren + +

Empfohlen für zuverlässigen E-Mail-Versand.

+
SMTP Host + +

z.B. smtp.gmail.com, smtp.ionos.de, mail.ihr-provider.de

+
SMTP Port + +

Standard: 587 (TLS), 465 (SSL), 25 (keine Verschlüsselung)

+
Verschlüsselung + +
SMTP Authentifizierung + +
SMTP Benutzername + +

Meist Ihre E-Mail-Adresse

+
SMTP Passwort + +

⚠️ Wird unverschlüsselt in der Datenbank gespeichert!

+
Debug-Modus + +

Nur für Fehlersuche aktivieren!

+
+ + +
+ +
+ +

Test-E-Mail senden

+
+ + + + + + +
Test-E-Mail an + + +
+
+ + +
+

E-Mail Logs (letzte 50)

+
+ + +
+ + + + + + + + + + + + + + + + + + + +
ZeitEmpfängerBetreffStatus
+ + +
+ +
+ + +
+

Häufige Probleme & Lösungen

+
+

E-Mails kommen nicht an?

+
    +
  1. Logs prüfen: Aktivieren Sie Debug-Modus und schauen Sie in wp-content/debug.log.
  2. +
  3. Gmail Nutzer: Verwenden Sie ein App-Passwort, nicht Ihr normales Passwort. Port 587 + TLS.
  4. +
  5. OpenSSL Fehler: Wenn im Log steht "openssl extension missing", kontaktieren Sie Ihren Hoster.
  6. +
  7. Firewall: Manche Hoster blockieren Port 25 und 587.
  8. +
+
+
+ -