So Im a front-end beginner and I ran into this problem. I searched high and low for anwsers and I my resoults were insufficient. Plx halp.
So this is how the situation looks like :
- Page is live, mail account has been configured (properly I guess) since it can recive and send mails.
- Server does suppport php5/php7
- Clicking submit button does return true value for mail being send
- PHP code does seem to be without a bug
- Mailer function is saved in a different file with the route as mentioned in action
Despite of all it this, when one does click to submit, message of success apears and the mail never gets through to the recipient
wat???
PHP CODE :
<?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 FORM:
<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>