0

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 :

  1. Page is live, mail account has been configured (properly I guess) since it can recive and send mails.
  2. Server does suppport php5/php7
  3. Clicking submit button does return true value for mail being send
  4. PHP code does seem to be without a bug
  5. 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 &rarr;</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: &quot;I'm tottaly enjoying your page!" required></textarea>
            <input type="submit" value="Shoot it! &rarr;" class="contact__btn btn">
            <?php
                if($_GET['success'] == 1) {
                    echo "<div class=\"contact__message succes\">Got it!</div>";
                }
            ?>
        </form>
Kaghar
  • 1
  • Could you check what the return value for the `mail()` function ? You redirect to success page but you actually don't check the return of the function. – JazZ Jan 27 '18 at 10:19
  • From [documentation](http://php.net/manual/en/function.mail.php), **Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise** – JazZ Jan 27 '18 at 10:22

0 Answers0