这是html
它称为contact.html php 是外部文件。
这是 php
<form action="mailer.php" method="post">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Contact Number</label>
<input name="number" type="text" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<br/>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
下面是 php,该文件名为 mailer.php。我需要知道这种形式是否有效,如果无效,可能出现什么问题。或者,如果您有其他建议。感谢帮助。
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$from = 'From:me';
$to = 'me@hotmail.com';
$subject = 'Hello';
$body = "From: $name\n E-Mail: $email\n Number: $number\n Message:\n $message";
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($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>You answered the anti-spam question incorrectly!</p>';
}
} else {
echo '<p>You need to fill in all required fields!!</p>';
}
}
?>