1

When using a html form to call php to send an email with the details in the form to an email address specified in the php. The php file name is added to the URL but no email is sent and the page shown in blank.

The website is being hosted on my.ionos.co.uk (1&1) using php 7.3.

<form method="post" action="contact-form.php">
    <input class="contact" type="text" name="Name" placeholder="Name">
    <input class="contact" type="text" name="Email" placeholder="Your Email Address">
    <input class="contact" type="text" name="Subject" placeholder="Subject">
    <textarea class="contact" name="Message" rows="10" placeholder="Message"></textarea>
    <input class="contact-submit" type="submit" value="Send Message">
</form> 
<?php

if(isset($_POST['submit'])) {
    $name = $_POST['Name'];
    $mailFrom = $_POST['Email'];
    $subject = $_POST['Subject'];
    $message = $_POST['Message'];

    $mailTo = "[email protected]";
    $headers = "From: ".$mailFrom;
    $txt = "You have recieved an email from ".$name.".\n\n".$Message;

    if(mail($mailTo, $subject, $txt, $headers)){
        echo "<h1>Mail send successfully</h1>";
    } else {
        echo "<h1>Mail failed to send<h1>";
    }
    header("Location: contact.html?mailsend");
}

?>

I'd appreciate it if someone could help, thanks in advance!

1
  • in contact-form.php try to add var_dump($_POST);. $_POST var is fine? Commented Jul 28, 2019 at 14:02

1 Answer 1

2

Try to change:

 if(isset($_POST['submit'])) {

with

 if(isset($_POST['Email'])) { //or another field in your form. If you want you can also add in your submit button: name="submit"

Checking out your code seems there is not an input with name submit. So you never enter in the if case.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I added name="submit" to the form
If you resolved your issues consider to accept the answer, thanks! meta.stackexchange.com/a/5235

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.