prize_for_day( (int) $day ); $sitename = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); $headers = self::mail_headers( $opts ); $replace = array( '{first}' => $entry->first_name, '{last}' => $entry->last_name, '{email}' => $entry->email, '{day}' => (int) $day, '{prize}' => $prize, '{losnr}' => $losnr, '{sitename}' => $sitename, ); // Participant confirmation (sent as a styled HTML mail). if ( ! empty( $opts['email_enabled'] ) && is_email( $email ) ) { $subject = strtr( (string) $opts['email_subject'], $replace ); $body = strtr( (string) $opts['email_body'], $replace ); $html = self::html_wrap( $subject, $body, $opts ); wp_mail( $email, $subject, $html, self::mail_headers( $opts, true ) ); } // Admin notification. if ( ! empty( $opts['admin_notify'] ) ) { $admin_email = is_email( $opts['admin_email'] ) ? $opts['admin_email'] : get_option( 'admin_email' ); $subject = sprintf( /* translators: %d: day number */ __( 'Neue Adventskalender-Teilnahme (Türchen %d)', 'adventura-interactive-advent-calendar' ), (int) $day ); $body = sprintf( /* translators: 1: name, 2: email, 3: day, 4: result, 5: los number */ __( "Neue Teilnahme:\n\nName: %1\$s\nE-Mail: %2\$s\nTürchen: %3\$d\nErgebnis: %4\$s richtig\nLos-Nr.: %5\$s", 'adventura-interactive-advent-calendar' ), trim( $entry->first_name . ' ' . $entry->last_name ), $entry->email, (int) $day, (int) $entry->correct_count . '/' . (int) $entry->total_questions, $losnr ); wp_mail( $admin_email, $subject, $body, $headers ); } } /** * Build wp_mail() headers with a custom From name/address so the plugin * mails are not sent as "WordPress ". Falls back to the site * name and admin address when the settings are empty. * * @param array $opts Plugin options. * @param bool $html Whether the mail body is HTML. * @return string[] */ public static function mail_headers( $opts, $html = false ) { $name = isset( $opts['email_from_name'] ) ? trim( (string) $opts['email_from_name'] ) : ''; if ( '' === $name ) { $name = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); } $from = isset( $opts['email_from_email'] ) ? $opts['email_from_email'] : ''; if ( ! is_email( $from ) ) { $from = get_option( 'admin_email' ); } $type = $html ? 'text/html' : 'text/plain'; $headers = array( 'Content-Type: ' . $type . '; charset=UTF-8' ); if ( is_email( $from ) ) { $headers[] = sprintf( 'From: %s <%s>', $name, $from ); } return $headers; } /** * Accent colour for the e-mail header, derived from the active theme (or the * custom accent when the custom palette is in use). * * @param array $opts Plugin options. * @return string Hex colour. */ private static function brand_accent( $opts ) { $theme = isset( $opts['theme'] ) ? (string) $opts['theme'] : 'beere'; if ( 'custom' === $theme ) { $hex = sanitize_hex_color( (string) ( $opts['custom_accent'] ?? '' ) ); if ( $hex ) { return $hex; } } $map = array( 'beere' => '#b4452e', 'tanne' => '#2f6b4f', 'amber' => '#b5701f', 'winter' => '#2f6ba8', 'ostern' => '#4f9a4a', 'halloween' => '#d67a1e', ); return isset( $map[ $theme ] ) ? $map[ $theme ] : '#b4452e'; } /** * Wrap a plain-text mail body in a simple, mail-client-safe HTML shell * (inline styles, table layout) branded with the site name and accent * colour. The plain text is escaped and its line breaks are preserved. * * @param string $heading Headline (usually the subject line). * @param string $text Plain-text body with {placeholders} already replaced. * @param array $opts Plugin options. * @param string $footer_html Optional trusted HTML appended in the footer (e.g. an unsubscribe link). * @return string HTML document body. */ public static function html_wrap( $heading, $text, $opts, $footer_html = '', $cta = null ) { $accent = self::brand_accent( $opts ); $sitename = esc_html( wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); $body = wpautop( esc_html( (string) $text ) ); $heading = esc_html( (string) $heading ); $font = "-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif"; // Optional call-to-action button (e.g. a double-opt-in confirm link). $cta_html = ''; if ( is_array( $cta ) && ! empty( $cta['url'] ) && ! empty( $cta['label'] ) ) { $cta_html = '
' . esc_html( $cta['label'] ) . '
'; } // Header: configured logo, otherwise the site name in the accent colour. $logo_id = isset( $opts['email_logo_id'] ) ? (int) $opts['email_logo_id'] : 0; $logo_html = ''; if ( $logo_id ) { $src = wp_get_attachment_image_url( $logo_id, 'medium' ); if ( $src ) { $logo_html = '' . esc_attr( $sitename ) . ''; } } $header_inner = '' !== $logo_html ? $logo_html : '' . $sitename . ''; // Footer: configurable text + copyright + optional unsubscribe link. $footer_text = isset( $opts['email_footer_text'] ) ? trim( (string) $opts['email_footer_text'] ) : ''; $footer = ''; if ( '' !== $footer_text ) { $footer .= '
' . nl2br( esc_html( $footer_text ) ) . '
'; } $footer .= '
© ' . esc_html( wp_date( 'Y' ) ) . ' ' . $sitename . '
'; if ( '' !== $footer_html ) { $footer .= '
' . $footer_html . '
'; } ob_start(); ?>