나는이 양식 작동 매우 간단하지만 효과적인 PHP 양식 핸들러를 필요로하는 것은 :PHP 문의 양식 처리기가 작동하지 않습니까?
<form id="contact" method="post" action="contact_handle.php">
<label for="name">Name:</label>
<input type="text" class="text_style" placeholder="John Doe" name="name" /><br />
<label for="email">Email:</label>
<input type="email" class="text_style" placeholder="[email protected]" name="email" /><br />
<label for="message">Subject:</label>
<textarea class="areawidth" rows="4" name="message" /></textarea><br />
<button id="contactbutton" type="submit">Submit</button>
</form>
이 내가 현재 가지고있는이지만 이메일을 보내하지 않고 내가 의도처럼 리디렉션하지 않습니다 . 그리고 나는 무슨 일이 일어나고 있는지 파악하는 것 같다.
<?php
$invalid = '';
$my_email = '[email protected]';
// Validate input:
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$invalid.= "\n All fields are required";
}
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
// Validate email:
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email))
{
$invalid .= "\n Invalid email address";
}
// Send email if no errors detected:
if(empty($invalid))
{
$to = $my_email;
$subject = "Contact form submission: $name";
$body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email\n Message:\n $message";
$headers = "From: $email\n";
$headers .= "Reply-To: $email";
mail($to,$subject,$body,$headers);
//redirect to the thank you page:
header('Location: contact_thanks.php');
}
?>
제출되면 contact_handle.php로 연결되어 공백으로 표시되고 리디렉션되지 않습니다.
로컬 호스트 또는 라이브 서버에서 테스트 중이십니까? 오류 메시지가 나타 납니까? –
폼 핸들러의 10 번째 줄에 오타가있는 것처럼 보입니다. 오류 메시지를'$ error' 변수에 저장하고있는 반면 나머지 코드는'$ invalid'이어야합니다. – Indrek
오타, 오타가 수정되었습니다. 여전히 동일한 결과가 나타납니다. localhost와 live server 모두에서 테스트를했는데 어느 것도 작동하지 않습니다. 오류 메시지가 표시되지 않습니다. 빈 화면과 이메일이 없습니다. –