简体   繁体   中英

Getting occasional blank emails sent from contact form

My website is www.photograsurfer.com and very occasionally, 3 times or so in the last couple of months, I will get an email sent to me from my contact form that has no information in it.

I am using validation so I did not think it was possible to send the form without filling out the information. I have tested the form many times with no issues, but am concerned that maybe something is wrong with the contact form.

The latest email said it was an unknown sender 'via 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>

Any ideas? Thanks!

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

// PHP parameters

Add this check to the top of your script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM