に変換する必要があるフォームオブジェクト $Global["replaceBr"] = array("opinion"); // サーバーの url Cookie の記憶に使用 //$Global["url"] = 'aic-tokai.com'; $Global["url"] = 'kulakula.info'; // *.html, *.php, email.txt の文字コード $Global["charCode"] = 'SJIS'; // メールの文字コード $Global["charCodeEmail"] = 'JIS'; main(); function main() { global $Global; if ($_POST["submit-confirmation"]) { // 入力完了 -> 確認/エラー画面へ移動 inSessionVariable(); $session = $_SESSION; $session = replaceTag($session); $session = replaceBr($session); // 必須項目入力チェック $isFail = false; foreach($Global["withoutFail"] as $key => $value) { $input = trim($session[$value]); //print $input; if (!$input) { $isFail = true; $session[$value] = '入力されていません。'; } } // メールアドレスチェック foreach($Global["checkEmail"] as $key => $value) { $input = trim($session[$value]); if (checkEmail($input) == false) { $isFail = true; $session[$value] = '正しく入力されておりません。'; } } $htmlErr = readHtml("err.html"); $htmlConfirmation = readHtml("confirmation.html"); foreach($Global["tagInput"] as $key => $value) { $target = sprintf("_%s_", $value); //printf("target = %s, value = %s, session-value = %s", $target, $value, $_SESSION[$value]); $htmlErr = str_replace($target, $session[$value], $htmlErr); $htmlConfirmation = str_replace($target, $session[$value], $htmlConfirmation); } if ($isFail == false) { // 入力確認画面表示 print $htmlConfirmation; } else { // 未入力 print $htmlErr; } } elseif ($_POST["submit-retry"]) { // ボタン 戻る $htmlInput = readHtml("mail.html"); foreach($Global["tagInput"] as $key => $value) { $target = sprintf("_%s_", $value); //printf("target = %s, value = %s, session-value = %s", $target, $value, $_SESSION[$value]); $htmlInput = str_replace($target, $_SESSION[$value], $htmlInput); } print $htmlInput; } elseif ($_POST["submit-sendemail"]) { putCookie(); sendEmail(); $htmlThanks = readHtml("thanks.html"); print $htmlThanks; } else { $htmlInput = readHtml("mail.html"); $htmlInput = replaceCookie($htmlInput); foreach($Global["tagInput"] as $key => $value) { $target = sprintf("_%s_", $value); //printf("target = %s, value = %s, session-value = %s", $target, $value, $_SESSION[$value]); $htmlInput = str_replace($target, '', $htmlInput); } print $htmlInput; } } // タグを文字に置き換える function replaceTag($a) { global $Global; foreach ($Global["tagInput"] as $key => $value) { $a[$value] = htmlspecialchars($a[$value]); //print $a[$value]; } return $a; } // 改行を
に置き換える function replaceBr($a) { global $Global; foreach ($Global["replaceBr"] as $key => $value) { // 改行のみや全角スペースのみの場合は空と見なす $b = preg_replace("/[\r\n\s\t ]/", '', $a[$value]); if (strlen($b) == 0) $a[$value] = ''; $a[$value] = nl2br($a[$value]); } return $a; } // メールアドレス入力チェック function checkEmail($email) { if (($email == "") or (!preg_match("/^[\w\-\.]+@[\w\-\.]+[a-z]$/", $email))){ return false; } return true; } // メール送信 function sendEmail() { global $Global; $toEmail = $Global["emailTo"]; //$addMailHeader = sprintf("From: %s\n", $Global["emailFrom"]); $addMailHeader = sprintf("From: \"%s\" <%s>\n", $_SESSION["txt-name"], $_SESSION["txt-email"]); $subject = mb_convert_encoding($Global["emailSubject"], $Global["charCodeEmail"], $Global["charCode"]); $subject = mb_encode_mimeheader($subject); $option = '-t'; $text = readText("email.txt"); $text = mb_convert_encoding($text, $Global["charCodeEmail"], $Global["charCode"]); foreach ($Global["tagInput"] as $key => $value) { $value = mb_convert_encoding($value, $Global["charCodeEmail"], $Global["charCode"]); $target = sprintf("_%s_", $value); $str = mb_convert_encoding($_SESSION[$value], $Global["charCodeEmail"], $Global["charCode"]); $text = str_replace($target, $str, $text); } $text = str_replace("_server-info_", getServerInfo(), $text); mail($toEmail, $subject, $text, $addMailHeader, $option); } function replaceCookie($text) { global $Global; foreach ($Global["saveCookie"] as $key => $value) { //printf("replaceCookie: %s = %s", $value, $_COOKIE[$value]); $target = sprintf("_%s_", $value); $text = str_replace($target, $_COOKIE[$value], $text); } return $text; } // クッキーの出力 function putCookie() { global $Global; $expire = time() + 60 * 60 * 24 * 30; // 30日 foreach ($Global["saveCookie"] as $key => $value) { $c = $_SESSION[$value]; setcookie($value, $c, $expire, '/', $Global["url"]); } // クッキーの読み出し //$cookie = $_COOKIE["name"]; // クッキーの削除 //setcookie("name", , 0, '/', $Global["url"]); } // postされた情報をセッション変数に格納 function inSessionVariable() { foreach($_POST as $key => $value) { $_SESSION[$key] = $value; } } function readHtml($fname) { $fh = fopen($fname, "r"); while ($line = fgets($fh)) { //$line = rtrim($line); // 改行を削除 $data .= $line; } return $data; } function readText($fname) { $fh = fopen($fname, "r"); while ($line = fgets($fh)) { //$line = rtrim($line); // 改行を削除 $data .= $line; } return $data; } function sessionStart() { session_start(); if (!isset($sessionID)) $sessionID = 10001; session_register("sessionID"); $sessionID++; //printf("session: %s", $sessionID); } // 送信者情報 function getServerInfo() { $str .= "RemoteAddr: " . $_SERVER["REMOTE_ADDR"] . "\n"; $str .= "RemoteHost: " . $_SERVER["REMOTE_HOST"] . "\n"; //$numContentLength = $_SERVER["CONTENT_LENGTH"]; $str .= "HttpUserAgent: " . $_SERVER["HTTP_USER_AGENT"] . "\n"; $str .= "HttpReferer: " . $_SERVER["HTTP_REFERER"];// . "\n"; return $str; } ?>