0

I'm having an issue with my html form sending to my email.

I have it set up so that it goes to a php file and it works fine, but when I change the filename from index.php to contact.php it doesn't send anymore.

contact.php:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="style/stylesheet.css">
        <script src="script/scripts.js"></script>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
    </head>
    <body>
        <div class="banner">
            <img src="images/banner.jpg">
        </div>
        <div class="navigation">
            <div class="navbar">
                <a href="index.html" class="active">Home</a>
                <a href="news.html">News</a>
                <div class="dropdown">
                    <button class="dropbtn">Parts 
                        <i class="fa fa-caret-down"></i>
                    </button>
                    <div class="dropdown-content">
                        <a href="cases.html">Cases</a>
                        <a href="motherboards.html">Motherboards</a>
                        <a href="processors.html">Processors</a>
                        <a href="graphics.html">Graphics Cards</a>
                        <a href="storage.html">Storage</a>
                        <a href="powersupplies.html">Power Supplies</a>
                        <a href="ram.html">RAM</a>
                        <a href="other.html">Other</a>
                    </div>
                </div>
                <div class="dropdown">
                    <button class="dropbtn">Builds 
                        <i class="fa fa-caret-down"></i>
                    </button>
                    <div class="dropdown-content">
                        <a href="#">Placeholder</a>
                        <a href="#">Placeholder</a>
                        <a href="#">Placeholder</a>
                        <a href="#">Placeholder</a>
                        <a href="#">Placeholder</a>
                        <a href="#">Placeholder</a>
                        <a href="#">Placeholder</a>
                        <a href="#">Placeholder</a>
                    </div>
                </div> 
                <div class="contact" id="navright">
                    <a href="contact.html" style="float:right;">Contact</a>
                </div>
            </div>
        </div>
        <div class="contact_page">
                <form class="contact_form" action="contactform.php" method="post">
                    <label>Full Name:</label><br/>
                    <input type="text" name="name" placeholder="Full Name"><br/>
                    <label>Your Email:</label><br/>
                    <input type="text" name="mail" placeholder="Email"><br/>
                    <label>Subject:</label><br/>
                    <input type="text" name="subject" placeholder="Subject"><br/>
                    <label>Message:</label><br/>
                    <textarea name="message" class="contacttext" placeholder="Message..."></textarea><br/>
                    <button class="submit" type="submit">Submit</button>
                </form>
        </div>
        <div class="footer">
            <div class="footertext">
                <p>Here at Terry's Computers we do not claim to own any of 
                    the products showed on this website.</p>
                <a href="contact.html"><p>Contact Us</p></a>
            </div>
        </div>
    </body>
</html>

contactform.php:

<?php

if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $subject = $_POST['subject'];
    $mailFrom = $_POST['mail'];
    $message = $_POST['message'];

    $mailTo = "terryjtowell@terrytowell.com";
    $headers = "From: ".$mailFrom;
    $txt = "You have received an Email from ".$name.".\n\n".$message;

    mail($mailTo, $subject, $txt, $headers);
    header("Location: contact.php?mailsend");
}

?>

It's not my web hoster because it worked with this file.

index.php:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="stylesheet.css">
        <meta charset="UTF-8">
        <title>Email Form</title>
    </head>
    <body>
        <main>
            <p class="header">E-MAIL FORM</p>
            <form class="contact-form" action="contactform.php" method="post">
                <p class="title">Your Name</p>
                <input type="text" name="name" placeholer="Full Name"><br/>
                <p class="title">Your E-Mail</p>
                <input type="text" name="mail" placeholer="Your E-mail"><br/>
                <p class="title">Subject</p>
                <input type="text" name="subject" placeholer="Subject"><br/>
                <p class="title">Message</p>
                <textarea name="message" maxrows="10" placeholder="Message"></textarea><br/>
                <button type="submit" name="submit"><h2>SUBMIT</h2></button><br/>
            </form>
        </main>
    </body>
</html>
CodeBoyCode
  • 2,227
  • 12
  • 29
  • Normally with the index.php it goes back to the same thing but with all the inputs cleared. The url changes from index.php to index.php?mailsend but with the new file it doesn’t do that, it goes to a blank white page after submitting – terryjtowell 37 mins ago delete – terryjtowell Sep 22 '18 at 20:37

1 Answers1

2

Your PHP line:

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

Will never execute because you need an element with the name of submit, but you have:

<button class="submit" type="submit">Submit</button>

Which you have in the example you say works. The solution should be as simple as adding a name attribute like this:

<button class="submit" name="submit" type="submit">Submit</button>
j08691
  • 204,283
  • 31
  • 260
  • 272