모든 것이 정확할 때라도 필드가 비어 있다고 계속 말합니다. Heres는 내 코드 :연락처 양식이 제대로 작동하지 않습니다. 로직이 될 수 있습니다.
<p>*All Fields Required</p>
<?php
if(!empty($reply)){
echo "<p class='notify'>$reply</p>";
}
unset($reply);
?>
<form method="post" action="index.php" id='contact'>
<fieldset>
<label>Name</label>
<input type='text' id="name" name="name" placeholder="type here" required value='<?php echo $name; ?>'>
<label>Email</label>
<input type='email' id="email" name="email" placeholder="type here" required value='<?php echo $email; ?>'>
<label>Message</label>
<textarea id="message" name="message" placeholder="type here" required><?php echo $message; ?> </textarea>
<p>Answer the following CAPTCHA question: </p>
<label for="captcha">What color is Snow Whites hair?</label>
<input type='text' name='captcha' id='captcha' size='5'required><br>
<label for='action'> </label>
<input id="submit" name="submit" type="submit" value="submit"><br>
</fieldset>
</form>
을 heres 내 index.php를 문서 그러므로 당신은 action
라는 이름의 양식 필드가없는
<?php
if($_POST['action']=='submit'){
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
$captcha=strtolower($_POST['captcha']);
}
if(empty($name)||empty($email)||empty($message)){
$reply='Sorry, one or more fields are empty. All fields are required.';
include 'contactform.php';
exit;
}
if(empty($captcha)|| $captcha != 'black'){
$reply='The captcha answer is incorrect.';
include 'contactform.php';
exit;
}
$finalmessage="Name:$name\n";
$finalmessage .="Email: $email\n";
$finalmessage .="Message: \n$message";
//sending the message
$to="[email protected]";
$from="From: $email";
$result= mail($to, $finalmessage, $from);
//Letting visitors know what happened
if($result ==TRUE){
$reply = "Thank you $name for contacting us.";
unset($name);
unset($email);
unset($message);
include 'contactform.php';
exit;
} else{
$reply='Sorry $name. There was an error and the message could not be sent';
unset($name);
unset($email);
unset($message);
include 'contactform.php';
exit;
}
?>
POST 배열에서 "조치"를 찾고있는 것처럼 보이지만 전송의 이름을 "제출"으로 설정하고 있습니다. 제출 이름을 변경해보십시오. –
양식을 확인하십시오. 'name = "action"'이있는 요소가 없습니다. 그래서,'$ _POST [ 'action']'은 절대로 설정되지 않습니다. 추신 왜'