0

我终于弄清楚了如何创建向下滑动的 Web 表单,但是我在哪里以及如何设置我的电子邮件地址。因此,当有人向我发送消息时,我会在电子邮件中收到相同的消息。我想这是一个基本问题,但我找不到答案。

这是 JSFiddle 的链接:http: //jsfiddle.net/8S82T/101/

<!doctype html>
<html>
<head>
    <title>Jquery test</title>

    <meta charset="UTF-8" />
    <link rel="stylesheet" type="text/css" href="main.css" />

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

</head>

<body>

    <div class="container">

        <div id="button" class="title">
            <h6>Contact</h6>
        </div>

        <div id="dropbox">
            <header class="title">
                <h6>Whats up?</h6>
            </header>

            <div class="contact-form">
                <form action="lulzy.php" action="post">
                        <h6><img src="img/person.png" alt="" /> Name</h6>
                    <input type="text" placeholder="Please enter your full name here" required />
                        <h6><img src="img/email.png" alt="" /> E-mail</h6>
                    <input type="email" placeholder="Please enter your e-mail address" required/>
                        <h6><img src="img/message.png" alt="" /> Message</h6>
                    <textarea placeholder="Type your message..." required/></textarea>

                    <input type="submit" value="Submit">
                </form>
            </div>
        </div>

    </div>

<script src="dropbox.js"></script>

</body>
</html>
4

4 回答 4

4

是一个很好的教程给你

它涉及到服务器端语言 PHP 的使用。

该脚本还特别使用了一些验证来确保向您发送内容的人不会向您发送垃圾邮件

您还需要将name属性添加到输入中。它们应该是nameemailcomments

<?php
if(isset($_POST['email'])) {

// CHANGE THE TWO LINES BELOW
$email_to = "you@yourdomain.com"; // put your email here

$email_subject = "Website HTML form submissions"; // put the subject here


function died($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
}

// validation expected data exists
if(!isset($_POST['name']) ||
    !isset($_POST['email'])     ||
    !isset($_POST['comments'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');      
}

$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
  $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
  $error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
  $error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
  died($error_message);
}
$email_message = "Form details below.\n\n";

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n
$email_message .= "Comments: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
?>

 <!-- place your own success html here -->

<?php
}
die();
?>
于 2013-05-25T15:12:01.407 回答
4

您已经将操作添加lulzy.php到表单中

您需要将以下代码添加到该文件中lulzy.php

<?php
  $name= $_REQUEST['name'] ;
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;

  mail( "yourname@example.com", "Feedback Form Results",
    $message, "From: $email" );
  header( "Location: http://www.example.com/thankyou.html" );
?>
于 2013-05-25T15:12:12.767 回答
3

好的,我已经在您的表单中添加了名称和 ID,并创建了一个 javascript 函数 validate()(我在我的标题中有)- 通过提供元素 ID,然后它通过 id 启用 getelement 如果所有字段都是,则 onsubmit 返回 false未输入。html 中的“email”元素更正了正确的电子邮件格式。php 是对垃圾邮件的双重检查。希望这可以帮助。

        <div class="contact-form">
            <form  onsubmit="return Validate();" action="lulzy.php" action="post" name="contact">
                    <h6><img src="img/person.png" alt="" /> Name</h6>
                <input type="text" placeholder="Please enter your full name here" name="fname" id="fname" />
                    <h6><img src="img/email.png" alt="" /> E-mail</h6>
                <input type="email" placeholder="Please enter your e-mail address" name="email" id="email"/>
                    <h6><img src="img/message.png" alt="" /> Message</h6>
                <textarea placeholder="Type your message..." name="message" id="message"/></textarea>
                 <input type="submit" value="Submit">
            </form>
        </div>

<script type="text/javascript">
    function Validate()
    {
        // create array containing textbox elements
        var inputs = [document.getElementById('fname'), document.getElementById('email'), document.getElementById('message')];

        var error;

        for(var i = 0; i<inputs.length; i++)
        // loop through each element to see if value is empty
        {
            if(inputs[i].value == '')
            {
                error = 'Please complete all fields.';
                alert(error);
                return false;
                }
        }
     }

 include ("contact.html");

    function spamcheck($field)
  {
  //filter_var() sanitizes the e-mail
  //address using FILTER_SANITIZE_EMAIL
  $field=filter_var($field, FILTER_SANITIZE_EMAIL);

  //filter_var() validates the e-mail
  //address using FILTER_VALIDATE_EMAIL
  if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
  }

if (isset($_POST['submit'])) {

    //process form data
  //check if the email address is invalid
  $mailcheck = spamcheck($_POST['email']);
 if ($mailcheck==TRUE){

  //send email
  $email=$_POST['email'];
  $fname=$_POST['fname'];
   $message = $_POST['message'] ;
  $subject="website contact";
  mail("your email address", $subject ,$message , "From: $email");
 echo '<script type="text/javascript"> alert("Your form has been submitted.")       

'

http://jsfiddle.net/yvytty/zLfgL/1/(没有php)

于 2013-05-25T15:38:29.513 回答
1

非常简单的解决方案,但也非常业余将改变action你的形式。你可以这样做:

action="mailto:yourmail@domain;com"

示例:http: //jsfiddle.net/ywah9/


更好的解决方案是创建一个提交页面,您可以在其中使用PHP. 小例子:

$body = 'New email submitted:' . $_POST['email'];
mail( 'yourmail@domain.ext' , 'Contact form website' , $body )

上面的例子是非常基本的,只是为了给你一个良好的开端!

于 2013-05-25T15:07:37.450 回答