简单的PHP结果消息以及其他一些要点

时间:2016-02-02 10:29:25

标签: php html

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" );
?>
  • 一旦有人,我想要显示一条感谢信息 成功填写表格
  • 我想查看正确的电子邮件ID,例如。如果&#34; @&#34;和&#34; .com&#34;已进入
  • 是否可以将条目保存到另一个php或文本文件?电子邮件发送后?

提前感谢所有回复!

1 个答案:

答案 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']);
}

您可以保存数据库提交后的条目吗?或者我认为你可以创建一个会话来保持变量以供进一步使用。在提交数据之后,您打算如何处理数据?