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!

A.Tressos
  • 35
  • 7
  • Your PHP code is not being executed. Is PHP installed properly on your WAMP server? – Jamie_D Oct 28 '18 at 18:24
  • See: [link]https://stackoverflow.com/questions/10600564/wamp-server-isnt-executing-php-code – Jamie_D Oct 28 '18 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(?) – A.Tressos Oct 28 '18 at 18:34

2 Answers2

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 ".

A.Tressos
  • 35
  • 7
0

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

  • "You should run the form code using server" — they are, they is why the screenshot shows `localhost` in the address bar. – Quentin Oct 29 '18 at 10:46
  • 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. – Wisken Whited Mar 08 '19 at 10:28