I am trying to create some code that sends an email from a form using php. If the email field is not filled out, I don't want the script to send the form. I am trying to do that using isset. The problem is that the php script (which is in a separate file, goes ahead and sends the mail whether or not the email field is filled out. In other words the email field seems to be always filled out even when it's not. Would anyone please help me to understand what is going wrong? Thank you!
Here is the code for the form on the first page which is called Contact.html:
Code: Select all
<div id="ContactText">
<form method="post" action="ContactSend.php">
<table width="300" border="0">
<tr>
<td align="right" valign="top"><p class="contactFormText">Name:</p></td>
<td class="contactFormText"><input type="text" name="fullname" id="tswname" /></td>
</tr>
<tr>
<td align="right" valign="top"><p class="contactFormText">Email:</td>
<td><input type="text" name="email" id="tsemail" /></td>
</tr>
<tr>
<td align="right" valign="top"><p class="contactFormText">Message:</td>
<td><textarea name="comments" id="tswcomments" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td align="right" valign="top"> </td>
<td><input type="submit" name="SubmitButton" id="SubmitButton" value="Send" /></td>
</tr>
</table>
</form>
</div>
Code: Select all
<?php
// if email field is filled out, send email. NOTE: This is the thing that doesn't work!
if (isset($_REQUEST['email']))
{
$Full_Name = $_REQUEST["fullname"];
$Email = $_REQUEST["email"];
$Comments = $_REQUEST["comments"];
$Body = "$Full_Name\r\n$Email\r\n$Comments";
mail("jherman@legendanimation.com", "Message from website", $Body, "From $Full_Name:");
echo "<p class='description'>Your message has been sent.</p>";
echo "<p class='description'>Thank you for contacting us.</p>";
}
else
// If email field is not filled out
{
echo "<p class='description'>A mail error has occurred.</p>";
echo "<p class='whatever'><a href='Contact.html'>Click here to try again</a>";
}
?>