index.phpで入力する値で"gender"だけが入力してるにもかかわらず、mail.phpによって送られてくるメールにgenderの値が取得されておりません。なぜかが判明しないのですがどこか間違っておりますでしょうか?
php
1 2index.php 3 4<!DOCTYPE html> 5<html lang="en"> 6<head> 7 <meta charset="utf-8"> 8 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 9 <meta name="viewport" content="width=device-width, initial-scale=1"> 10 <meta name="description" content="Bootstrap contact form with PHP example by BootstrapBay.com."> 11 <meta name="author" content="BootstrapBay.com"> 12 <title>Bootstrap Contact Form With PHP Example</title> 13 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"> 14</head> 15<body> 16 <div class="container"> 17 <div class="row"> 18 <div class="col-md-6 col-md-offset-3"> 19 <h1 class="page-header text-center">FORM</h1> 20 <form class="form-horizontal" role="form" method="post" action="mail.php"> 21 22 <div class="form-group"> 23 <label for="name" class="col-sm-2 control-label">Name</label> 24 <div class="col-sm-10"> 25 <input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="<?php echo htmlspecialchars($_POST['name']); ?>"> 26 <?php echo "<p class='text-danger'>$errName</p>";?> 27 </div> 28 </div> 29 30 <!-- radio --> 31 <div class="form-group"> 32 <label class="col-sm-2 control-label">gender</label> 33 <div class="col-sm-10"> 34 <div class="radio-inline"> 35 <label> 36 <input type="radio" name="gender" id="man" value="<?php echo htmlspecialchars($_POST['gender']); ?>"> 37 man 38 </label> 39 </div> 40 <div class="radio-inline"> 41 <label> 42 <input type="radio" name="gender" id="woman" value="<?php echo htmlspecialchars($_POST['gender']); ?>"> 43 woman 44 </label> 45 </div> 46 </div> 47 </div> 48 49 <div class="form-group"> 50 <label for="email" class="col-sm-2 control-label">Email</label> 51 <div class="col-sm-10"> 52 <input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com" value="<?php echo htmlspecialchars($_POST['email']); ?>"> 53 <?php echo "<p class='text-danger'>$errEmail</p>";?> 54 </div> 55 </div> 56 57 <div class="form-group"> 58 <label for="message" class="col-sm-2 control-label">Message</label> 59 <div class="col-sm-10"> 60 <textarea class="form-control" rows="4" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea> 61 <?php echo "<p class='text-danger'>$errMessage</p>";?> 62 </div> 63 </div> 64 65 <div class="form-group"> 66 <label for="human" class="col-sm-2 control-label">2 + 3 = ?</label> 67 <div class="col-sm-10"> 68 <input type="text" class="form-control" id="human" name="human" placeholder="Your Answer"> 69 <?php echo "<p class='text-danger'>$errHuman</p>";?> 70 </div> 71 </div> 72 73 <div class="form-group"> 74 <div class="col-sm-10 col-sm-offset-2"> 75 <input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary"> 76 </div> 77 </div> 78 79 <div class="form-group"> 80 <div class="col-sm-10 col-sm-offset-2"> 81 <?php echo $result; ?> 82 </div> 83 </div> 84 85 </form> 86 </div> 87 </div> 88 </div> 89 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 90 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script> 91 92 93</body> 94</html>
php
1 2mail.php 3 4<?php 5 if (isset($_POST["submit"])) { 6 $name = $_POST['name']; 7 $gender = $_POST['gender']; 8 $email = $_POST['email']; 9 $message = $_POST['message']; 10 $human = intval($_POST['human']); 11 $from = 'Demo Contact Form'; 12 $to = 'my e-mail'; 13 $subject = 'Message from Contact Demo '; 14 15 $body ="From: $name\n Gender: $gender\n E-Mail: $email\n Message:\n $message\n"; 16 // Check if name has been entered 17 if (!$_POST['name']) { 18 $errName = 'Please enter your name'; 19 } 20 21 // Check if email has been entered and is valid 22 if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { 23 $errEmail = 'Please enter a valid email address'; 24 } 25 26 //Check if message has been entered 27 if (!$_POST['message']) { 28 $errMessage = 'Please enter your message'; 29 } 30 //Check if simple anti-bot test is correct 31 if ($human !== 5) { 32 $errHuman = 'Your anti-spam is incorrect'; 33 } 34 // If there are no errors, send the email 35 if (!$errName && !$errEmail && !$errMessage && !$errHuman) { 36 if (mail ($to, $subject, $body, $from)) { 37 $result='<div class="alert alert-success">Thank You! I will be in touch</div>'; 38 } else { 39 $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>'; 40 } 41 } 42 } 43 ?> 44
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/10 20:02
退会済みユーザー
2016/12/10 20:06
2016/12/11 04:45