Upload folder via GUI - inc
This commit is contained in:
102
inc/classes/class-mailer.php
Normal file
102
inc/classes/class-mailer.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class WMF_Mailer {
|
||||
|
||||
/**
|
||||
* Admin-Benachrichtigung
|
||||
*/
|
||||
public static function notify_admin($form_id, $meta, $fields, $values, $file_values = array()) {
|
||||
$global = get_option('wmf_global_settings', array());
|
||||
$from_name = !empty($meta['from_name']) ? $meta['from_name'] : ($global['from_name'] ?? get_bloginfo('name'));
|
||||
$from_email = !empty($meta['from_email']) ? $meta['from_email'] : ($global['from_email'] ?? get_option('admin_email'));
|
||||
$to = !empty($meta['admin_email']) ? $meta['admin_email'] : get_option('admin_email');
|
||||
$subject = !empty($meta['admin_subject']) ? $meta['admin_subject'] : 'Neue Formulareinreichung';
|
||||
|
||||
$headers = array(
|
||||
'Content-Type: text/html; charset=UTF-8',
|
||||
'From: ' . $from_name . ' <' . $from_email . '>',
|
||||
);
|
||||
|
||||
// Reply-To auf Absender-E-Mail-Feld setzen
|
||||
if(!empty($meta['admin_reply_to']) && $meta['admin_reply_to'] === '1') {
|
||||
foreach($fields as $f) {
|
||||
if(($f['type'] ?? '') === 'email' && !empty($values[$f['id']]) && is_email($values[$f['id']])) {
|
||||
$headers[] = 'Reply-To: ' . $values[$f['id']];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wp_mail($to, $subject, self::build_body($fields, $values, $file_values), $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Absender-Bestaetigung
|
||||
*/
|
||||
public static function notify_sender($form_id, $meta, $fields, $values) {
|
||||
$global = get_option('wmf_global_settings', array());
|
||||
$from_name = !empty($meta['from_name']) ? $meta['from_name'] : ($global['from_name'] ?? get_bloginfo('name'));
|
||||
$from_email = !empty($meta['from_email']) ? $meta['from_email'] : ($global['from_email'] ?? get_option('admin_email'));
|
||||
|
||||
$email = '';
|
||||
foreach($fields as $f) {
|
||||
if(($f['type'] ?? '') === 'email' && !empty($values[$f['id']]) && is_email($values[$f['id']])) {
|
||||
$email = $values[$f['id']];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!$email) return;
|
||||
|
||||
$headers = array(
|
||||
'Content-Type: text/html; charset=UTF-8',
|
||||
'From: ' . $from_name . ' <' . $from_email . '>',
|
||||
);
|
||||
|
||||
$body = '<html><body style="font-family:sans-serif;color:#1d2327;max-width:600px;margin:0 auto;">'
|
||||
. wpautop(esc_html($meta['sender_message'] ?? ''))
|
||||
. '<p style="color:#888;font-size:12px;margin-top:24px;">Gesendet ueber ' . get_bloginfo('name') . '</p>'
|
||||
. '</body></html>';
|
||||
|
||||
wp_mail($email, $meta['sender_subject'] ?? 'Ihre Nachricht wurde empfangen', $body, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* E-Mail-Body aufbauen
|
||||
*/
|
||||
private static function build_body($fields, $values, $file_values) {
|
||||
$rows = '';
|
||||
foreach($fields as $f) {
|
||||
if(in_array($f['type'] ?? '', array('html','divider','hidden'))) continue;
|
||||
$lbl = $f['label'] ?? $f['id'];
|
||||
$val = $values[$f['id']] ?? '';
|
||||
if(is_array($val)) $val = implode(', ', $val);
|
||||
if(($f['type'] ?? '') === 'gdpr')
|
||||
$val = ($val === '1') ? '✓ Zugestimmt' : '✗ Nicht zugestimmt';
|
||||
if(($f['type'] ?? '') === 'signature' && !empty($val))
|
||||
$val = '<img src="' . esc_attr($val) . '" style="max-width:300px;border:1px solid #ddd;">';
|
||||
if(isset($file_values[$f['id']])) {
|
||||
$links = array_map(
|
||||
fn($u) => '<a href="' . esc_url($u['url']) . '">' . esc_html($u['name']) . '</a>',
|
||||
$file_values[$f['id']]
|
||||
);
|
||||
$val = implode('<br>', $links);
|
||||
}
|
||||
$rows .= '<tr>'
|
||||
. '<th style="text-align:left;padding:8px 14px;background:#f6f7f7;border-bottom:1px solid #eee;white-space:nowrap;font-weight:600;">' . esc_html($lbl) . '</th>'
|
||||
. '<td style="padding:8px 14px;border-bottom:1px solid #eee;">' . $val . '</td>'
|
||||
. '</tr>';
|
||||
}
|
||||
|
||||
return '<html><body style="font-family:Arial,sans-serif;color:#1d2327;max-width:600px;margin:0 auto;">'
|
||||
. '<div style="background:#2271b1;padding:20px 24px;border-radius:4px 4px 0 0;">'
|
||||
. '<h2 style="color:#fff;margin:0;font-size:18px;">Neue Formulareinreichung</h2>'
|
||||
. '<p style="color:rgba(255,255,255,.8);margin:4px 0 0;font-size:13px;">' . get_bloginfo('name') . ' · ' . current_time('d.m.Y H:i') . '</p>'
|
||||
. '</div>'
|
||||
. '<div style="border:1px solid #dcdcde;border-top:none;border-radius:0 0 4px 4px;padding:0;">'
|
||||
. '<table style="border-collapse:collapse;width:100%;">' . $rows . '</table>'
|
||||
. '</div>'
|
||||
. '<p style="color:#888;font-size:11px;margin-top:16px;text-align:center;">Diese E-Mail wurde automatisch gesendet von WP Multi Formular</p>'
|
||||
. '</body></html>';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user