nassu
if (isset($_POST['mfa_submit'])) { /* nonceチェック */ if (!isset($_POST['mfa_nonce']) || !wp_verify_nonce($_POST['mfa_nonce'], 'mfa_form_action')) { return '
不正な送信です
'; } $mail_body = "フォームから新しい送信がありました。\n\n"; $reply_to = ''; $attachments = []; foreach ($order as $key) { if (get_option("mfa_{$key}_show") !== '1') continue; $name = get_option("mfa_{$key}_name", "項目"); $type = get_option("mfa_{$key}_type", "text"); /* ===== ファイルは別処理 ===== */ if ($type === 'file') continue; $val = isset($_POST["mfa_in_{$key}"]) ? sanitize_text_field($_POST["mfa_in_{$key}"]) : "(入力なし)"; if (empty($reply_to) && is_email($val)) { $reply_to = $val; } $mail_body .= "【" . $name . "】\n" . $val . "\n\n"; } /* ===== ファイル添付処理 ===== */ if (!empty($_FILES)) { require_once(ABSPATH . 'wp-admin/includes/file.php'); foreach ($_FILES as $file) { if ($file['error'] === UPLOAD_ERR_OK) { $upload = wp_handle_upload($file, ['test_form' => false]); if (!isset($upload['error'])) { $attachments[] = $upload['file']; } } } } $target_email = get_option('mfa_admin_email', get_option('admin_email')); $subject = "【通知】" . get_bloginfo('name'); /* ★重要:Fromは書かない */ $headers = array(); $headers[] = 'Content-Type: text/plain; charset=UTF-8'; if (!empty($reply_to)) { $headers[] = 'Reply-To: ' . $reply_to; } $sent = wp_mail($target_email, $subject, $mail_body, $headers, $attachments); if (!$sent) { return 'メール送信に失敗しました
'; } $thanks_msg = get_option('mfa_thanks_msg', "送信ありがとうございました。"); return '' . nl2br(esc_html($thanks_msg)) . '