简体   繁体   中英

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 = "mashashapa@yandex.ru";
$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.

在此处输入图片说明 在此处输入图片说明

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM