spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / php / phpemail / 3 To page 1To page 2current pageTo page 4
[previous][next]

Email Forms in PHP

Developer News
Eclipse Helios Update Brings New PHP Tools
Internet Explorer 9 Ups Standards Support
JBoss Portal 5 Release Easier to Use

<?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 ("noone@nowhere.com", "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.

home / programming / php / phpemail / 3 To page 1To page 2current pageTo page 4
[previous][next]

webref The latest from WebReference.com Browse >
Flashmaps' DynamicLocator: Interactive Maps for Small Areas · Flashmaps' AreaSelector: Interactive Maps for Wide Areas · The DB Mapper: Interactive Street-level Maps of U.S. and Canada
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags


Created: July 30, 2001
Revised: July 30, 2001


URL: http://webreference.com/programming/javascript/phpemail/3.html