Spacecoreflake
Spacecoreflake

Reputation: 41

Redirecting from html to php

I am trying to write a website from scratch and try to add a form. but if i click on the Submit button (which redirects to the contact.php) it should send a mail without opening any email program, but it wont redirect properly... I googled and didnt find anything...

the code of that form is:

<!--Some code over this code-->
               <form action="contact.php" method="post">
                 <font color="ffffff">
        <center>
           <div>
              <label for="name">Name:</label>
              <input type="text" id="name" />
           </div>
            <div>
              <label for="Username">Username(s):</label>
              <input type="text" id="name" />
            </div>
           <div>
              <label for="Job">Job:</label>
              <select name="Job">
                 <option value="Artist">Artist</option>
                 <option value="Musican">Musican</option>
                 <option value="Props">Props</option>
                 <option value="Voice">Voice</option>
                 <option value="Effects">Effects</option>
              </select>

           </div>
        <div> 
               <div>
                   <label>THE THING</label><br><br>
                   <input type="checkbox" name="Program" value="Skype">I have SKYPE<br>
                   <input type="checkbox" name="Program" value="Steam">I have STEAM <br>
                   <input type="checkbox" name="Program" value="Origin">I have ORIGIN <br>
                   <input type="checkbox" name="Program" value="Teamspeak">I have TEAMSPEAK <br>
               </div>
        </div>
           <div>
              <label for="Message">Message:</label>
              <textarea id="Message"></textarea>
           </div>
           <br>
           <div class="button">
              <button type="submit">Send your message</button> <button type="reset">Clear the fields</button>
           </div>
        </center>
     </font>
            </form>
<!-- More code from my html -->

but when i now click on that button which should redirect from the index.html to contact.php it just gives an error (I tried Google drive and Github to host and on Dropbox it just wants to download the contact.php...) Gdrive error: 404 Page not found, Github: 405 no permission and like i said, dropbox just wants to download the file...

The code of the PHP:

<?php
$ToEmail = '[email protected]';
$EmailSubject = 'NEW CONTACT! READ IT STOOPID';
$mailheader = "From: ".$_POST["name"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["name"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Username: ".$_POST["Username"]."";
$MESSAGE_BODY .= "Job: ".$_POST["Job"]."";
$MESSAGE_BODY .= "Program".$POST["Program"]."";
$MESSAGE_BODY .= "Message: ".nl2br($_POST["Message"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>

<center><h1>Thank you :D!</h1></center>

Is it because i use such cheap websites to host? I just dont want to spent thousands of bucks into a little site i created for planning, as well as learning HTML...

Upvotes: 4

Views: 109

Answers (2)

Richard Parnaby-King
Richard Parnaby-King

Reputation: 14891

Welcome to StackOverflow.

Your error message says "gdrive and github cannot find the file". That is because, although they have your file, they are not set up to execute your files as PHP. Your issue here is that you are trying to run a php script in a non-server environment. You can set up a server environment on your own PC using XAMPP or WAMP Server. If you're using a Mac, you can use MAMP (free version or Pro).

Once you have installed the server bundle, you will have the most common Apache/PHP/MySQL setup. You will need to install your code in the X:/xampp/htdocs 1 folder (by default). To run your scripts, open your browser and go to http://localhost.

Also, domain name and hosting can cost as little as £16 per year for a .co.uk domain. .coms cost more. Other Top-Level Domains (TLDs) are available.


  1. 'X' is the drive letter for the drive in which you installed XAMPP or similar. For WAMP, use X:/wamp/www.

Upvotes: 3

tesst
tesst

Reputation: 159

I think your «websites to host» does not support PHP. You need web server like «apache» for supporting PHP scripts. You can test this by creating a file called 'test.php' (or give it another name, just make sure it has .php as extention) and put in the following code:

<?php phpinfo() ?>

If your host supports PHP, you should get a confirmation while opening test.php with the PHP version they are running. If you do not see this confirmation, your host does not support PHP.

Upvotes: 1

Related Questions