dtx6087 2016-02-02 10:29
浏览 18

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

Html Code (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 code (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']." 
";

$body .= "Email: ".$_REQUEST['Email']." 
";
# 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" );
?>
  • I want to display a thank you message once the person has successfully filled in the form
  • I want to check for correct email id eg. if "@" and ".com" has been entered
  • would it be possible to save the entries to another php or text file ? after the email has been sent ?

Thanks in advance for all replies!

  • 写回答

1条回答 默认 最新

  • dongtiao5094 2016-02-02 11:18
    关注

    There is a redirect once the mail is sent. Can you place your thank you message on this page? Sometimes I have a thank you.php page for this purpose.

    Here is a snippet from a contact form to check for email validation will this help?

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

    You could save the entries a database once submitted? Or I think you can create a session to keep hold of the variables for further use. What are you planning to do with the data then after it has been submitted?

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集