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
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

<?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]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


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


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