この記事を読まれている方におすすめ一覧クリック
コンタクトフォームのテンプレート属性を選ぶことができなくなりました。
ですが、
間違いに気づきましたので改めて記載します。
アドセンス336pxPC閲覧記事下表示1つ目コード
正式なphpコードは以下です。
<?php /* Template Name: お問い合わせフォーム*/?>
<?php
if(isset($_POST['submitted'])) {
//項目チェック
if(trim($_POST['checking']) !== '') {
$captchaError = true;
} else {
//名前の入力なし
if(trim($_POST['contactName']) === '') {
$nameError = '名前が入力されていません';
$hasError = true;
} else {
$name = trim($_POST['contactName']);
}
//メールアドレスの間違い
if(trim($_POST['email']) === '') {
$emailError = 'メールアドレスが入力されていません';
$hasError = true;
} else if (!preg_match('|^[0-9a-z_./?-]+@([0-9a-z-]+.)+[0-9a-z-]+$|', trim($_POST['email']))) {
$emailError = 'メールアドレスが正しくありません';
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//お問い合わせ内容の入力なし
if(trim($_POST['comments']) === '') {
$commentError = 'お問い合わせ内容が入力されていません';
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['comments']));
} else {
$comments = trim($_POST['comments']);
}
}
//エラーなしの場合、メール送信
if(!isset($hasError)) {
mb_language("japanese");
mb_internal_encoding("UTF-8");
$emailTo = get_option('admin_email');
$subject = 'お問い合わせ';
$body = "お名前: $name nnメールアドレス: $email nnお問い合わせ内容: $comments";
$title = get_bloginfo('name');
$from = mb_encode_mimeheader(mb_convert_encoding("$titleのお問い合わせ","UTF-8"));
$headers = 'From: '.$from.' <'.$emailTo.'>';
mb_send_mail($emailTo, $subject, $body, $headers);
//自動返信用
$subject = 'お問い合わせ受付のお知らせ';
$from = mb_encode_mimeheader(mb_convert_encoding("$title","UTF-8"));
$headers = 'From: '.$from.' <'.$emailTo.'>';
$body = "$name 様 nnお問い合わせありがとうございます。n改めて担当者よりご連絡をさせていただきます。nnお名前: $name nnメールアドレス: $email nnお問い合わせ内容: $comments";
mb_send_mail($email, $subject, $body, $headers);
$emailSent = true;
}
}
} ?>
<?php get_header(); ?>
<main>
<?php if(isset($emailSent) && $emailSent == true) { ?>
<h1 class="entry-title archive-title"><?=$name;?>様、お問い合わせありがとうございます。</h1>
メールを確認次第、返事をさせて頂きます。
<?php } else { ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<h1 class="entry-title archive-title"><?php the_title(); ?></h1>
<?php the_content(); ?>
<form action="<?php the_permalink(); ?>" id="contactForm" method="post">
<ol class="forms">
<li><label for="contactName">お名前</label>
<input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="requiredField" />
<?php if($nameError != '') { ?>
<span class="error"><?=$nameError;?></span>
<?php } ?>
</li>
<li><label for="email">メールアドレス</label>
<input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="requiredField email" />
<?php if($emailError != '') { ?>
<span class="error"><?=$emailError;?></span>
<?php } ?>
</li>
<li class="textarea"><label for="commentsText">お問い合わせ内容</label>
<textarea name="comments" id="commentsText" rows="20" cols="30" class="requiredField"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
<?php if($commentError != '') { ?>
<span class="error"><?=$commentError;?></span>
<?php } ?>
</li>
<li class="buttons"><input type="hidden" name="submitted" id="submitted" value="true" /><button type="submit">送信する</button></li>
</ol></form>
<?php endwhile; ?>
<?php endif; ?>
<?php } ?>
</main>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
上記のようにphpファイルを新たに作って(作成)エディターでUTF-8にて保存してFTPソフトでテーマと同じディレクトリにアップロードします。
そうすると、
普通(通常通り)に以下の画像のように、
固定ページ作成においても「テンプレート属性」をお問い合わせフォームに選択できるようになります。

※1行目の<php?の後に半角スペースがなかったので追加しただけです。
以上でプラグインを使わなくてもコンタクトフォームが作成できます。
以上でプラグインなしでコンタクトフォームを作ることができます。
参考になれば幸いです。
comment