Skip to content Skip to sidebar Skip to footer

Website Contact Form Not Sending Email

So I recently uploaded my first website to an iPage server. The website runs perfectly with the exception of the Contact Form which for some reason refuses to send any email whatso

Solution 1:

From what i see in the code you posted, the PHP mailing script won't work as you are checking if a POST variable with the name 'submit' exists which it does not as in your form the submit button does not have a name attribute. Try giving the submit button a name and put that name in the PHP if statement.

Solution 2:

Submit button name is missing in your form, You need to add name into your submit button,

  <inputtype="submit" name="submit"id="contactForm_submit"class="btn btn-trans btn-border btn-full" value="Submit">
                       ^^^^^^^^^^^^

instead of

  <inputtype="submit"id="contactForm_submit"class="btn btn-trans btn-border btn-full" value="Submit">

Solution 3:

Your HTML part should be something like below,

<formaction = "js/mailer.php"method="post"name="contactform"id="contactform"class="form validate item_bottom"role="form"><divclass="form-group"><inputtype="text"name="name"id="name"class="form-control required"placeholder="Name"></div><divclass="form-group"><inputtype="email"name="email"id="email"class="form-control required email"placeholder="Email"></div><divclass="form-group"><textareaname="message"id="message"class="form-control input-lg required"rows="9"placeholder="Enter Message"></textarea></div><divclass="form-group text-center"><inputtype="submit"name="sendemail"id="contactForm_submit"class="btn btn-trans btn-border btn-full"value="Submit"></div></form>

In above, I have added name="sendemail" in submit button.

And your PHP script that sends email should be like

<?phpif(isset($_POST['sendemail'])) { // <-- variable name changed$to = "aravindm3095@gmail.com";
    $subject = "Hello Aravind!";

    // data the visitor provided$name_field = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
    $email_field = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
    $comment = filter_var($_POST['message'], FILTER_SANITIZE_STRING);

    //constructing the message$body = " From: $name_field\n\n E-Mail: $email_field\n\n Message:\n\n $comment";
    $headers = "From: " . $email_field; // <-- Code added
    mail($to, $subject, $body, $headers); // <-- Code added// redirect to confirmation
    header('Location: confirmation.html');
    exit;
} else {
    echo"Failure";
}
?>

Post a Comment for "Website Contact Form Not Sending Email"