0

I am a Windows 7 user and I am creating a website on localhost:8080/ using XAMPP. I want to make a contact form using PHP for getting the data from the form(name, email, message) and sending them to my email. Here's what the form looks like in html so far:

<form class="contact-form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
    <br>
    <input type="text" name="name" placeholder="Name">
    <br><br>
    <input type="email" name="email" placeholder="E-mail (required)" required>
    <br><br>
    <textarea name="message" placeholder="Type your message here..." rows="5" cols="30"></textarea>
    <br><br>
    <input type="submit" name="submit" value="Submit">
</form>

I am using the following PHP script:

<body>
    <?php
        $emailValidation = "";
        if (filter_has_var(INPUT_POST, 'submit')) {
            $email = $_POST['email'];
            $name = $_POST['name'];
            $message = $_POST['message'];

            if (!empty($email) && !empty($name) && !empty($message)) {

            } else {

            }

            if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
              $emailValidation = "Invalid email format";
            }
        }
    ?>
.....stuff
</body>

When I submit the form the following error appears: enter image description here

I have tried modifying the httpd-vhosts.conf file by adding the following lines:

<Directory "C:/xampp/htdocs/ColdBeatz-Site">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order Deny,Allow
    Allow from all
    Require all granted
</Directory>

... but the problem remains!

NOTE: If I use a file (eg. contact.php) on action attribute, it is working fine!

3
  • Your PHP code is not being executed. Is PHP installed properly on your WAMP server? Commented Oct 28, 2018 at 18:24
  • See: [link]stackoverflow.com/questions/10600564/… Commented Oct 28, 2018 at 18:27
  • I haven't installed any PHP, apparently XAMPP has PHP already installed. If it wasn't installed, the "contact.php" file wouldn't be executed as well(?) Commented Oct 28, 2018 at 18:34

2 Answers 2

0

I solved the problem.

I just had to create a file called ".htaccess" at the same path with my html file and write the line: " AddType application/x-httpd-php .htm .html ".

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

Comments

0

You should run the form code using server. I think that you should not run the form code in HTML file.

2 Comments

"You should run the form code using server" — they are, they is why the screenshot shows localhost in the address bar.
Maybe you didn't set all the settings in the setting files such as config and index.php files. Please set all the config files correctly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.