0
我剛開始使用PHP並做了一些教程。我剛剛構建了以下PHP聯繫表單,但標題中的PHP語法出現在網頁中,我完全不確定爲什麼?可能值得一提的是我也將這個文件保存爲contactForm.php而不是contactForm.html(這是否有所作爲)。這裏有什麼問題?PHP/HTML5聯繫表格 - 什麼是錯誤
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title> Exercise: Contact Form</title>
<link type="text/css" rel="stylesheet" href="css/myStyle.css" />
<?php
$name = $_POST ['name'];
$email = $_POST ['email'];
$message = $_POST ['message'];
$from = 'From: Me';
$to = '[email protected]';
$subject = 'Hello';
$human = $_POST ['human'];
$body = "From $name\n Email: $email\n Message: $message\n";
if ($_POST ['submit'] && $human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
}
else{
echo '<p>Something went wrong, please try again.</p>';
}
}
else if ($_POST ['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly.</p>';
}
?>
</head>
<body>
<header>
<h1>My Test Page</h1>
</header>
<form id="testForm" method="post" action="contactForm.php">
<label>Name:</label>
<input class="input-fields" type="text" name="name" placeholder="Name" />
<label>E-mail:</label>
<input class="input-fields" type="email" name="email" placeholder="Email Address" />
<label>Message:</label>
<textarea class="input-fields" name="message" placeholder="Enter Message here" rows="5"></textarea>
<label>What is 2 + 2?</label>
<input class="input-fields" name="human" placeholder="Enter Answer">
<input type="submit" name="submit" id="submit" value="Click to Submit" />
</form>
</body>
這裏是它如何顯示圖像...
您是在服務器上運行此操作還是在瀏覽器本地打開頁面? – j08691
你使用什麼網絡服務器? –
只是在瀏覽器本地,只是想測試回聲,以確保他們對錶單驗證作出反應。 – tom1bomb