所以我是一名前端初学者,我遇到了这个问题。我搜索了高低不同的东西,我的灵魂不足。 Plx halp。
所以情况就是这样:
尽管如此,当点击提交时,成功的消息和邮件永远不会传递给收件人
笏???
PHP代码:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form fields, removes html tags and whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["message"]);
// Check the data.
if (empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: http://www.xxx.pl/index.php?success=-1#contact");
exit;
}
$recipient = "yyy@xxx.pl";
// Set the email subject.
$subject = "New contact from $name";
// Build the email content.
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Message:\n$message\n";
// Build the email headers.
$email_headers = "From: $name <$email>";
// Send the email.
mail($recipient, $subject, $email_content, $email_headers);
// Redirect to the index.html page with success code
header("Location: http://www.xxx.pl/index.php?success=1#contact");
} else {
echo "There was a problem with your submission, please try again.";
}
?>
HTML表格:
<footer class="footer" id="contact">
<a href="https://github.com/xxx" target="_blank" class="footer__git--link"><i class="icon-github footer__git--icon"></i></a>
</div>
<form method="post" action="vendor/php/mailer.php" class="contact">
<label for="name">What's Your name?</label>
<input type="text" name="name" id="name" pattern="[a-zA-Z]*" required>
<label for="email">Toss Your email here →</label>
<input type="email" name="email" id="email" required>
<label for="message">Do tell!</label>
<textarea name="message" id="message" cols="30" rows="10" placeholder="For instance: "I'm tottaly enjoying your page!" required></textarea>
<input type="submit" value="Shoot it! →" class="contact__btn btn">
<?php
if($_GET['success'] == 1) {
echo "<div class=\"contact__message succes\">Got it!</div>";
}
?>
</form>