Masha312
Masha312

Reputation: 1

php form does not work

I am trying to create a form that would send the data to my email, but when I test the form, I get "this webpage is not found/ No webpage was found for the web address: file:///C:/Users/Masha/Dropbox/nam%20fp/contact.php". And, my email box is empty as well.

Here's my html code:

<html>
<head>
<link rel = "stylesheet" type = "text/css" href = "mystylec.css">
</head>

<body>
<h1>
    CONTACT
</h1>

<? = $thankYou ?>

<form method = "post" action = "contact.php">
    <br><br> e-mail: <br>
    <input type = "text" name = "senderEmail" value = "" required>
    <br><br>
    name: <br>
    <input type = "text" name = "sender" value = "">
    <br><br>
    comment: <br>
    <textarea name = "comment" rows = "10" cols = "30"></textarea required>
    <br><br>
    <input type = "submit" value = "submit">
</form>
<h3>
<img src = "https://img-fotki.yandex.ru/get/5301/julia- kropacheva.27/0_59f4f_6bb21bc3_orig" alt = "uzor" style = "width:468px;height:755px;"/>
</h3>

</body>
</html>

And here is my php:

if($_POST["submit"])
{
$recipient = "[email protected]";
$subject = "NAM Advertising request";
$sender = $_POST["sender"];
$senderEmail = $_POST["senderEmail"];
$message = $_POST["comment"];

$mailBody = "Name: $sender\nEmail: $senderEmail\n\n$comment";

mail($recipient, $subject, $mailBody, "From: $sender $sender <$senderEmail>");

$thankyou = "<p> Thank you! Your form has been submitted. </p>";
}

?>

Also, I attached screenshots of what happens when I try to submit the form.

enter image description here enter image description here

Thank you all! I feel like this might be a simple problem, but I just started coding so I don't get a lot of stuff.

Upvotes: 0

Views: 68

Answers (2)

Alexander Rossa
Alexander Rossa

Reputation: 2080

In order to test PHP, you have to do it on a server (PHP is a server-side scripting language). The best way to do this will be to use something like XAMPP or WAMP which function as your local server on which you can test your scripts etc. before deploying them. Since you are running Windows, it is just a matter of taste as to which one to choose.

Read the documentation and happy scripting.

Upvotes: 1

fabian enos
fabian enos

Reputation: 71

PHP is a server side language. This means that PHP script must be served by a web server(such as Apache) that has PHP installed. Every time your script is called, the web server will call and then wait for PHP to execute your code before showing you the results it generates.

Have a look at this link that @Armen had mentioned in the comments: How to configure your XAMPP server

Upvotes: 1

Related Questions