我有一个关于使这两段代码一起工作的问题。我已经经历了几天努力寻找为什么这会产生一个指向contact.php而不是发送带有数据的电子邮件的空白页面。只需姓名、公司名称和电子邮件。我不是 php 程序员,希望能得到帮助,或者如果有人能引导我朝着正确的方向前进。
HTML5 示例
<form method="post" action="contact.php">
<fieldset>
<label for="alerts-name">Your Name</label>
<input type="text" name="name" id="alerts-name" class="input" maxlength="30">
</fieldset>
<fieldset>
<label for="alerts-business">Business Name</label>
<input type="text" name="business" id="alerts-business" class="input" maxlength="50">
</fieldset>
<fieldset>
<label for="alerts-email">Your email</label>
<input type="text" name="email" id="alerts-email" class="input" maxlength="30">
</fieldset>
<label>*What is 2+2? (Anti-spam)</label><br />
<input name="human" placeholder="Type Here">
<fieldset>
<br />
<fieldset>
<input type="submit" value="submit">
</fieldset>
</form>
下面是我正在使用的 php 代码。
<?php
$name = $_POST['name'];
$business = $_POST['business'];
$email = $_POST['email'];
$from = 'From: The Web Site';
$to = 'myemail@site.com';
$subject = 'Hello';
$human = $_POST['human'];
$body = "From: $name\n business: $business\n email:\n $email";
if ($_POST['submit'] && $human == '4') {
if (mail ($to, $name, $business, $email) ) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>