メールフォーム

mail_input 入力画面
mail_check 確認画面 (エラーなどがあった場合があるので必須)
mail_thank 送信完了の画面(お問い合わせありがとうございます。)

mail_input.php

名前/メールアドレス/メッセージ/送信の作成

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>無題ドキュメント</title>
</head>
<body>
<div id="container">
  <form action="mail_check.php" method="post">
    <table>
      <tr>
        <th> <label for="name" >名前</label></th>
        <td><input type="text" size="20" maxlength="12" name="name" id="name"></td>
      </tr>
      <tr>
        <th> <label for="email">メールアドレス</label>
        </th>
        <td><input type="text" size="40" maxlength="50" name="email" id="email"></td>
      </tr>
      <tr>
        <th> <label for="name">メッセージ</label>
        </th>
        <td><textarea name="message" rows="5"></textarea></td>
      </tr>
      <tr>
        <th colspan="2"> <input type="submit" value="送信" class="btn">
        </th>
      </tr>
    </table>
  </form>
</div>
</body>
</html>

mail_check.php

確認画面の受け皿作成

  • 1つ1つ指定する。
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>確認画面</title>
<?php
var_dump($_POST);
?>
</head>
<body>
<h1>確認画面</h1>
<table>
  <tr>
    <th>名前</th>
    <td><?php print htmlspecialchars($_POST['name'],ENT_QUOTES,'utf-8');?></td>
  </tr>
  <tr>
    <th>メール</th>
    <td><?php print htmlspecialchars($_POST['email'],ENT_QUOTES,'utf-8');?></td>
  </tr>
  <tr>
    <th>テキスト</th>
    <td><?php print htmlspecialchars($_POST['message'],ENT_QUOTES,'utf-8');?></td>
  </tr>
</table>
</body>
</html>
  • htmlが入力し終わった時点で、var_dump($_POST);を行う。
    (これでエラーが出た場合は、htmlのコード自体に問題があるといえる)
  • ユーザー定義関数を指定したパターン
<?
function h($str){
	return htmlspecialchars($str,ENT_QUOTES,'utf-8');
}
var_dump($_POST);
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>確認画面</title>
<style>
table,tr,th,td{
	border-collapse:collapse;
	border:1px #DEC1C1 dotted;
	width:600px;
}
</style>
</head>
<body>
<h1>確認画面</h1>
<table>
  <tr>
    <th>名前</th>
    <td><?php print h($_POST['name']); ?></td>
  </tr>
  <tr>
    <th>メール</th>
    <td><?php print h($_POST['email']); ?></td>
  </tr>
  <tr>
    <th>テキスト</th>
    <td><?php print h($_POST['message']); ?></td>
  </tr>
</table>
</body>
</html>