1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
<?php //error_reporting(-1); //ini_set('display_errors', 'On'); session_start(); if (isset($_POST["nn"]) && $_POST["token"] == $_SESSION["token"]) { $smtp = ""; $to = ""; $subject = "件名"; $message = "名前:" . h($_POST["nn"]); $from = ""; ini_set("SMTP", $smtp); ini_set("smtp_port","587"); mb_language("japanese"); mb_internal_encoding("UTF-8"); mb_send_mail($to, $subject, $message, "From:" . $from); echo "<script>(function(){alert('送信しました。');}());</script>"; } else { } $_SESSION["token"] = md5(mt_rand()); function h($s){ return htmlspecialchars($s, ENT_QUOTES, "UTF-8"); } ?> <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>お問い合わせテスト</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <form action="" method="post" id="ff"> 名前:<input type="text" name="nn" id="nn"> <input type="submit" value="送信"> <input type="hidden" name="token" value="<?php echo $_SESSION["token"]; ?>"> </form> <script> $("#ff").submit(function(){ if($("#nn").val() == ""){ alert("名前の入力は必須です。") return false; } return true; }); </script> </body> </html> |