Hi everyone. I’m brand new to PHP and I’m having difficulties getting this simple script to work. Basically what I’m trying to do is build a form in HTML which asks for the user’s name and email address, and then sends that information to a php script that will send an email to that user. Here’s my attempt at it.
Here’s the code in the HTML form. This file is named formPractice.html:
[code]
<!DOCTYPE public HTML “-//W3C//DTD XHTML 1.1//EN”
“http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” lang=”en”>
<head>
<title>PHP & Form practice</title>
<meta http-equiv=”content-type” content=”text/html; charset=”ISO-8895-1″/>
</head>
<body>
<form action=”formPractice.php” method=”post”>
<p>Please input your name:<br/>
<input type=”text” name=”name” id=”name”/>
</p>
<p>
Now input your email address:<br/>
<input type=”text” name=”email” id=”email”/>
</p>
<input type=”submit” name=”submit” id=”submit” value=”submit”/>
</form>
</body>
</html>
and here’s the code for the php file that will handle the form data. This file is named formPractice.php:
[code]
<?php
$email = $_POST[“email”];
$name = $_POST[“name”];
$emailBody = “Thank you for placing your order with us “.$name.”. You will be receiving your
package in a day or two. If you have any questions please feel free to contact me (415)378-
9068.”;
mail($email, “confirmation”, $emailBody);
?>
When I open the file called formPractice.html and fill in the form entries, and click the submit button, I get a dialog box that asks me which program I want to use to open up the formPractice.php file and instead of executing that file, it’ll just open and display the contents. Is there something I’m missing here?
Also, how come on my laptop, I can’t save the document as a php file. I create the script in notepad and when I go to save it I name it something like phpDocument.php, but when I look at the file type it’s still a text file with the name phpDocument.php. So basically it’s phpDocument.php.txt. But when I do the same thing on my desktop, I get the desired file type.