我已经看到了许多与此类似的问题,但是由于我是 PHP 新手,所以我无法将函数放在正确的位置。我在 PHP 和 HTML 中拼凑了一些东西,但我似乎在该$radio
地区遗漏了一些东西。有没有人有什么建议?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$radio = isset($_POST['radio']) ? $_POST['radio'] : 'default';
switch ($radio) {
case 'Eval CH':
$to = 'blah@blah.com';
break;
case 'Eval ELL':
$to = 'sigh@sigh.com';
break;
}
$message = $_POST['message'];
$from = 'From: WAC Site';
$subject = 'WAC Contact Message';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
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, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>Either you are a robot, or you are very, very bad at math.</p>';
}
?>
这是我的 HTML:
<form method="post" action="contact_options.php">
<label>Name</label><br>
<input name="name" placeholder="Type Here"><br>
<br>
<label>Email</label><br>
<input name="email" type="email" placeholder="Type Here"><br>
<br>
<input type="radio" name="Eval CH" value="to">Email Blah<br>
<input type="radio" name="Eval ELL" value="to">Email Sigh<br>
<label>Message</label><br>
<textarea name="message" placeholder="Type Here"></textarea><br>
<br>
<label>*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here"><br />
<input id="submit" name="submit" type="submit" value="Submit"><br>
</form>