Html代码(index.html)
<div id="stable" class="center-div" >
<form method="POST" action="send.php">
<input type="text" name="FNAME" value="FIRST NAME" size="20" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;">
<!--<input type="text" name="LNAME" value="LAST NAME" size="20" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;">-->
<input type="text" name="Email" VALUE="EMAIL" size="20" style="font-size:13px; height:50px; background-color:#f5f5f5"onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;">
<input type="submit" value="Submit" name="Submit" class="button">
</div>
</form>
Php代码(send.php)
<?php
## CONFIG ##
# LIST EMAIL ADDRESS
$recipient = "admin@gmail.com";
# SUBJECT (Subscribe/Remove)
$subject = "Someone wants updates!";
# RESULT PAGE
$location = "index.html";
## FORM VALUES ##
# SENDER - WE ALSO USE THE RECIPIENT AS SENDER IN THIS SAMPLE
# DON'T INCLUDE UNFILTERED USER INPUT IN THE MAIL HEADER!S
$sender = $recipient;
# MAIL BODY
$body .= "Name: ".$_REQUEST['FNAME']." \n";
$body .= "Email: ".$_REQUEST['Email']." \n";
# add more fields here if required
## SEND MESSGAE ##
mail( $recipient, $subject, $body, "From: $sender" ) or die ("Mail could not be sent.");
## SHOW RESULT PAGE ##
header( "Location: $location" );
?>
提前感谢所有回复!
答案 0 :(得分:0)
邮件发送后会有重定向。你能把谢谢你的消息放在这个页面上吗?有时为此我有一个感谢you.php页面。
以下是联系表单中的一个片段,用于检查电子邮件验证是否有帮助?
if(trim($_POST['email']) === '') {
} else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
$emailError = 'You entered an invalid email address.';
$hasError = true;
} else {
$email = trim($_POST['email']);
}
您可以保存数据库提交后的条目吗?或者我认为你可以创建一个会话来保持变量以供进一步使用。在提交数据之后,您打算如何处理数据?