从联系表单中偶尔收到空白电子邮件

时间:2014-04-12 22:50:33

标签: php contact-form

我的网站是www.photograsurfer.com,并且偶尔会在过去几个月内3次左右,我会收到一封通过我的联系表单发送给我的电子邮件,其中没有任何信息。

我正在使用验证,所以我认为没有填写信息就可以发送表单。我已经多次测试过表格而没有任何问题,但我担心联系表格可能有问题。

最新的电子邮件说,这是一个未知的发件人'来自web2000.websitewelcome.com'

<?php

// PHP parameters
$sendto = "jefe.damron@gmail.com";
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

// Subject
$email_subject = $_POST['name'] . ' ' . 'is contacting you from Photograsurfer.com' . '!';


// body of email
$body = "
<html>
<head>

<style type='text/css'>

        body{
            width: 500px;
            font-size: 1em;
            letter-spacing: .1em;
            color: rgb(166,166,166);
        }

        li {
            list-style: none;
            padding: 5px 0px 0px 5px;
            font-size: 1.350em;
            background-color: rgb(230,230,230);
            margin-left: 5px;
        }

        ol {
            padding: 5px 0 5px 30px;
            background-color: rgb(245,245,245);
            margin-top: 0;
            margin-left: 5px;
            font-size: 1.15em;
        }

</style>

</head>
<body>

<div>

    <ul>

        <li>Name:</li>
            <ol>- $name</ol>

        <li>Email:</li>
            <ol>- $email</ol>

        <li>Message:</li>
            <ol>- $message</ol>

    </ul>

</div>


</body>
</html>
";

$body = wordwrap($body, 60, "\n");

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: $email";

// Mail it
  mail( $sendto, $email_subject, $body, $headers );
?>

$(document).ready(function () {

    $("#contactform").validate({
        rules: {
            name: {
                required: true,
                minlength: 2
            },
            email: {
                required: true,
                email: true
            },
            message: {
                required: true,
                minlength: 10
            },
        },
        messages: {
            name: {
                required: "*Please enter your name.",
                minlength: "*Your name must consist of at least 2 characters."
            },
                email: "*Please enter a valid email address.",
                message: "*Please, say something at least 10 characters long.",
        },

        submitHandler: function(form) {
            $('#submitemail').hide();
            $("#contactform li.buttons").append('<img src="http://www.photograsurfer.com/media/loading.gif" alt="Loading" id="loading" />');
            $.post('http://www.photograsurfer.com/code/submitcontactform.php',
            $('form#contactform').serialize());

            setTimeout( function() {
                $("#contactform").slideUp("normal", function() {                   
                $("#contactform").before('<img src="http://www.photograsurfer.com/media/contact_thankyou.png" alt="Thank You" id="thankyou" />');

                })
            },2000);

            return false;
        }
        })
        return false;
});

<form id="contactform" method="post">
        <ol class="forms">
            <fieldset>
                <label for="name"><input type="text" name="name" id="name" value="" placeholder="Name:" required minlength="2" /></label>
            </fieldset>
                <p style="margin-top: -15px;"><label for="name" class="error"></label></p> 
            <fieldset>
                <label for="email"><input type="text" name="email" id="email" value="" placeholder="Email:" required /></label>
            </fieldset>
                <p style="margin-top: -15px;"><label for="email" class="error"></label></p>           
            <fieldset>
                <label for="message"><textarea name="message" id="message" placeholder="Question/Comments:" required ></textarea></label>
            </fieldset>
                <p style="margin-top: -10px;"><label for="message" class="error"></label></p>            
            <li class="buttons"><button type="submit" id="submitemail">Send Email &raquo;</button><input type="hidden" name="submitted" id="submitted" value="true" /></li>

        </ol>
    </form>

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:2)

if (!isset($_REQUEST['name']) || !isset($_REQUEST['email']) || !isset($_REQUEST['message'])) {
  die();
}

// PHP parameters

将此检查添加到脚本的顶部。