<?php
if(isset($_POST['submit'])){
$subject = $_POST['subject'];
$text = $_POST['elvismail'];
$output_form=false;
echo $subject.$text ;
if(empty($subject)&&empty($text)){
echo 'You forgot the mail subject and body text.<br />';
$output_form =true;
}
if(empty($subject)&&!(empty($text))){
echo 'You forgot the mail subject.<br />';
$output_form =true;
}
if((!empty($subject))&&empty($text)){
echo 'You forgot the mail body text.<br />';
$output_form =true;
}
if((!empty($subject))&&(!empty($text))){
echo 'submit already .<br />';
}
}
else{
$output_form = true;
}
$output_form = true;
if($output_form){
?>
<form method="post" action="index.php">
<label for ="subject"> subject of email:</label><br />
<input id ="subject" name="subject" type="text" size="30"/> <br />
<label for ="elvismail"> body of email:</label><br />
<textarea id="elvismail" type ="text" name="elvismail" rows="8" cols="40"> </textarea> <br />
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
}
?>
注意在 textarea框会自动填入空格,导致$text非空。