I have a function embedded into an XHTML page. It's pretty simple. If $POST['submit'] isn't set, it prints out a form with a submit button. If it is set, it emails the contents of the form via the $POST array.
Here's how it looks:
<?php
function show_form() {
print <<<HTMLBLOCK
<form action="aboutusphp.htm" method="post">
<table width="400" cellpadding="0">
<tr>
<td width="100">
<p>Name:</p>
<td width="300">
<input type="text" name="name" size="40" maxlength="60" value="" />
</td>
</tr>
<tr>
<td width="100">
<p>Company:</p>
</td>
<td width="300">
<input type="text" name="company" size="40" maxlength="60" value="" />
</td>
</tr>
<tr>
<td width="100">
<p>Address:</p>
</td>
<td width="300">
<input type="text" name="address" size="40" maxlength="60" value="" />
</td>
</tr>
<tr>
<td width="100">
<p>City:</p>
</td>
<td width="300">
<input type="text" name="city" size="40" maxlength="60" value="" />
</td>
</tr>
<tr>
<td width="100">
<p>State:</p>
</td>
<td width="300">
<input type="text" name="state" size="2" maxlength="2" value="" />
</td>
</tr>
<tr>
<td width="100">
<p>Zip Code:</p>
</td>
<td width="300">
<input type="text" name="zipcode" size="5" maxlength="5" value="" />
</td>
</tr>
<tr>
<td width="100">
<p>Phone:</p>
</td>
<td width="300">
<input type="text" name="phone" size="20" maxlength="20" value="" />
</td>
</tr>
<tr>
<td width="100">
<p>Fax:</p>
</td>
<td width="300">
<input type="text" name="fax" size="20" maxlength="20" value="" />
</td>
</tr>
<tr>
<td width="100">
<p>Email:</p>
</td>
<td width="300">
<input type="text" name="email" size="40" maxlength="40" value="" />
</td>
</tr>
<tr>
<td width="100">
<p>Website Needs:</p>
</td>
<td width="300">
<textarea rows="10" cols="40" name="needs"></textarea>
</td>
<tr>
<td width="100">
<input type="submit" name="submit" value="Submit" />
</tr>
</table>
</form>
HTMLBLOCK;
}
if(! isset($_POST['submit'])) {
show_form();
}
else {
$headers = "From: $_POST['name']\r\n"
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;\r\n charset=\"iso-8859-1\"\r\n";
$body = "
<html>
<head>
<title>Contact Form</title>
</head>
<body>
<p>Name: $_POST['name']</p>
<p>Company: $_POST['company']</p>
<p>Address: $_POST['address']</p>
<p>City: $_POST['city']</p>
<p>State: $_POST['state']</p>
<p>Zip: $_POST['zipcode']</p>
<p>Phone: $_POST['phone']</p>
<p>Fax: $_POST['fax']</p>
<p>Email: $_POST['email']</p>
<p>Web needs: $_POST['needs']</p>
</body>
</html>
";
mail("myemail", "Web Design Request", $body, $headers);
}
?>
Right now, it seems like the HTMLBLOCK isn't closing. When the page gets viewed, HTMLBLOCK; and everything after it just gets printed out onto the web page rather than being evaluated as PHP. Everything before the HTMLBLOCK; seems to be evaluted fine. I.E the function declaration doesn't get printed or anything but the form outputs OK as HTML.
And I don't if it's related, but the 'submit' button does nothing right now. You can click to your heart's content and nothing changes.