Jordan Basran
Jordan Basran

Reputation: 13

PHP file name added to URL but not called from html

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!

Upvotes: 1

Views: 50

Answers (1)

icy
icy

Reputation: 1446

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.

Upvotes: 2

Related Questions