我刚开始使用PHP并做了一些教程。我刚刚构建了以下PHP联系表单,但标题中的PHP语法渗入网页,我完全不确定为什么?值得一提的是,我还将此文件保存为contactForm.php而不是contactForm.html(这有什么不同)。这有什么不对?
<!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@email.co.uk';
$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>
以下是它如何显示的图像......
答案 0 :(得分:0)
PHP必须在具有php引擎的Web服务器上运行。它无法从桌面上的文件直接在浏览器中运行。