if (isset($_POST['mfa_submit'])) {

    /* nonceチェック */
    if (!isset($_POST['mfa_nonce']) || !wp_verify_nonce($_POST['mfa_nonce'], 'mfa_form_action')) {
        return '<p style="color:red;">不正な送信です</p>';
    }

    $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 '<p style="color:red;">メール送信に失敗しました</p>';
    }

    $thanks_msg = get_option('mfa_thanks_msg', "送信ありがとうございました。");

    return '<div style="background:#e7f5ea; border:2px solid #52c41a; padding:30px; text-align:center; max-width:'.esc_attr($form_width).'px; margin:20px auto; border-radius:8px;">
                <h2 style="color:#237804;">送信完了</h2>
                <p>' . nl2br(esc_html($thanks_msg)) . '</p>
            </div>';
}<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet type='text/xsl' href='https://terawa.com/wp-content/plugins/google-sitemap-generator/sitemap.xsl'?><!-- sitemap-generator-url='http://www.arnebrachhold.de' sitemap-generator-version='4.1.23' -->
<!-- generated-on='2026-04-29 04:25' -->
<sitemapindex xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd' xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>	<sitemap>
		<loc>https://terawa.com/sitemap-misc.xml</loc>
		<lastmod>2026-04-24T01:18:59+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://terawa.com/category-sitemap.xml</loc>
		<lastmod>2026-04-24T01:18:59+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://terawa.com/post-sitemap.xml</loc>
		<lastmod>2026-04-24T01:18:59+00:00</lastmod>
	</sitemap>
</sitemapindex><!-- Request ID: 1caf3ed32cdc38ebcaab2138f2392d64; Queries for sitemap: 5; Total queries: 44; Seconds: 0; Memory for sitemap: 1KB; Total memory: 12MB -->
