contact form 7 のお問い合わせのテンプレート

管理側

確認画面は、「Contact Form 7 add confirm」というプラグインを使う。
公式:https://ja.wordpress.org/plugins/contact-form-7-add-confirm/

<table>
  <tr>
    <th scope="row">お名前</th>
    <td>[text your-name]</td>
  </tr>
  <tr>
    <th>メールアドレス<span class="required">必須</span></th>
    <td>[email* inquiry_mail placeholder email "例)your-email@example.com"]</td>
  </tr>
  <tr>
    <th>メールアドレス(確認用)<span class="required">必須</span></th>
    <td>[email* inquiry_mail_confirm]</td>
  </tr>
  <tr>
    <th scope="row">お電話</th>
    <td>[tel your-tel]</td>
  </tr>
  <tr>
    <th scope="row">郵便番号(ハイフン不要)</th>
    <td>[text zip 7/7 id:zip]</td>
  </tr>
  <tr>
    <th scope="row">ご住所</th>
    <td>[text address id:address]</td>
  </tr>
  <tr>
    <th scope="row">お問合せ内容</th>
    <td>[textarea your-message] </td>
  </tr>
</table>

<p class="submit">[confirm "確認画面へ"][back "戻る"][submit "送信する"]</p>

題名:ホームページからお問い合わせがありました。

メッセージ:

差出人: [your-name] <[inquiry_mail]>

ホームページより以下のお問い合わせがありました。

メッセージ本文:
お名前:[your-name]
メールアドレス:[inquiry_mail]
確認用メールアドレス:[inquiry_mail_confirm]
電話番号:[your-tel]
郵便番号:[zip]
住所:[address]
お問い合わせ内容:[your-message]

自動返信側

題名:○○○○○○○○○○です。お問い合わせありがとうございます。

自動返信内容:

[your-name] 様

お問い合わせありがとうございます、○○○○ です。
お問い合わせを受付いたしました。
あらためて担当者よりご連絡させていただきます。

以下、お客様お問い合わせ内容:
お名前:[your-name]
メールアドレス:[inquiry_mail]
確認用メールアドレス:[inquiry_mail_confirm]
電話番号:[your-tel]
郵便番号:[zip]
住所:[address]
お問い合わせ内容:[your-message]

もし間違いがございましたら、お電話もしくはホームページのお問い合わせフォーム、もしくは以下のメールアドレスよりご連絡くださいませ。
E-mail:○○○○○○○○○○@△△△△.□□□

本メールは自動返信専用メールです。
このメールにご返信いただくことはできません。

以下をfunctions.phpに記載して、確認用メールアドレスが動作するようにする。

// コンタクトフォームのメアド再入力
function wpcf7_main_validation_filter( $result, $tag ) {
  $type = $tag['type'];
  $name = $tag['name'];
  $_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );
  if ( 'email' == $type || 'email*' == $type ) {
    if (preg_match('/(.*)_confirm$/', $name, $matches)){
      $target_name = $matches[1];
      if ($_POST[$name] != $_POST[$target_name]) {
        if (method_exists($result, 'invalidate')) {
          $result->invalidate( $tag,"確認用のメールアドレスが一致していません");
      } else {
          $result['valid'] = false;
          $result['reason'][$name] = '確認用のメールアドレスが一致していません';
        }
      }
    }
  }
  return $result;
}

add_filter( 'wpcf7_validate_email', 'wpcf7_main_validation_filter', 11, 2 );
add_filter( 'wpcf7_validate_email*', 'wpcf7_main_validation_filter', 11, 2 );

送信完了ページが必要な場合は以下をfunctions.phpに記載する。送信完了用固定ページが必要。

add_action( 'wp_footer', 'add_thanks_page' );
function add_thanks_page() {
echo <<< EOD
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
  location = 'https://haniwaman.com/thanks/'; /* 遷移先のURL */
}, false );
</script>
EOD;
}
ページトップへ移動