Email Forms in PHP - (3/4)
[previous][next] |
Email Forms in PHP
<?php
if (($Name == "") || ($Email == "") || ($Comments == ""))
{
echo "<form name=form method=post action=contact_thanks.php>";
echo "<p class=bodymd>All three fields of this form are required, I really don't think that's too much to ask...</p>";
echo "<p class=bodymd>Fill in the ones you missed, they are listed below.</p>";
}
if ($Name == "")
{
echo "<p class=bodymd>Your Name<br><input type=text name=Name></p>";
}
else
{
echo "<input type=hidden name=Name value=$Name>";
}
if ($Email == "")
{
echo "<p class=bodymd>Your Email<br><input type=text name=Email></p>";
}
else
{
echo "<input type=hidden name=Email value=$Email>";
}
if ($Comments == "")
{
echo "<p class=bodymd>Comments or Questions<br><textarea name=Comments rows=5 cols=40></textarea></p>";
}
else
{
echo "<input type=hidden name=Comments value=$Comments>";
}
if (($Name == "") || ($Email == "") || ($Comments == ""))
{
echo "<input type=submit name=Submit value=Submit>";
echo "<input type=reset name=Reset value=Clear Form>";
echo "</form>";
}
else
{
$message = "Name: $Name\nEmail: $Email\nComments: $Comments\n";
$extra = "From: $Name\r\nReply-To: $Email\r\n";
mail ("[email protected]", "Website Email", $message, $extra);
echo "<p class=bodymd>Thanks for your inguiry, $Name.</p>";
echo "<p class=bodymd>A response will be sent to $Email as soon as possible.</p>";
}
?>
<?php
if (($Name == "") || ($Email == "") || ($Comments == ""))
{
echo "<form name=form method=post action=contact_thanks.php>";
echo "<p class=bodymd>All three fields of this form are required, I really don't think that's too much to ask...</p>";
echo "<p class=bodymd>Fill in the ones you missed, they are listed below.</p>";
}
if ($Name == "")
{
echo "<p class=bodymd>Your Name<br><input type=text name=Name></p>";
}
else
{
echo "<input type=hidden name=Name value=$Name>";
}
if ($Email == "")
{
echo "<p class=bodymd>Your Email<br><input type=text name=Email></p>";
}
else
{
echo "<input type=hidden name=Email value=$Email>";
}
if ($Comments == "")
{
echo "<p class=bodymd>Comments or Questions<br><textarea name=Comments rows=5 cols=40></textarea></p>";
}
else
{
echo "<input type=hidden name=Comments value=$Comments>";
}
if (($Name == "") || ($Email == "") || ($Comments == ""))
{
echo "<input type=submit name=Submit value=Submit>";
echo "<input type=reset name=Reset value=Clear Form>";
echo "</form>";
}
else
{
$message = "Name: $Name\nEmail: $Email\nComments: $Comments\n";
$extra = "From: $Name\r\nReply-To: $Email\r\n";
mail ("[email protected]", "Website Email", $message, $extra);
echo "<p class=bodymd>Thanks for your inguiry, $Name.</p>";
echo "<p class=bodymd>A response will be sent to $Email as soon as possible.</p>";
}
?>
The final if statement above is again checking for empty fields. If any of the required fields are empty, it will print submit and clear buttons as well as the closing form tag to complete the form that has been opened earlier for re-submission. Once re-submitted it will be re-validated by the same process. Once all of the required fields are filled in, it then hits the else option of the last if. This is where the mail is processed and sent.
[previous][next] |
Created: July 30, 2001
Revised: July 30, 2001
URL: https://webreference.com/programming/javascript/phpemail/3.html