broken php form/script (worked for years)
Posted by: al-khowarizmi
Posted on: 2008-10-07 17:42:00
I have a contact form and associated php script that worked together for years. A while back I thought of testing it and the script returns the if..else error based on an empty message. I'm not competent with forms or php but this is simple straightforward stuff and I just can't see why it should fail, unless something basic as changed in php syntax? Can anyone spot the error?
Form:
<form method="POST" action="script.php">
<table border="0" cellspacing="8" cellpadding="0">
<tr>
<td align="right">Name:</td>
<td>
<input type="text" name="name" size="32" maxlength="50">
</td>
</tr>
<tr>
<td align="right">Email:</td>
<td>
<input type="text" name="addy" size="32" maxlength="50">
</td>
</tr>
</table>
Your Message:
<textarea name="comments" wrap=physical cols="56" rows="12"></textarea>
<input type="submit" value="Send">
<input type="reset" value="Cancel">
</form>
Script:
<?php
if ($comments != ""):
$message = "Name: " . $name . "\nEmail: " . $addy . "\n\n" . $comments . "\n";
mail ("richardj@example.com", "Contact page feedback!", $message, "From: richard@example.com");
?>
...acknowledgment html...
<?php
else:
?>
...error html...
<?php
endif;
?>