如何从我的PHP代码中停止幻影电子邮件?

时间:2015-08-04 01:24:17

标签: php html5 email verification

我目前正在使用带有联系表格和php动作的html5网站来接收联系电子邮件。我已经在我的PHP中尝试了几个不同的代码,但没有阻止空白的电子邮件来。我的代码确实启用了google analytics,但是已经通过robot.txt阻止了抓取工具。这是我的代码。

PHP代码

<?php
foreach ($_GET as $Field=>$Value) { 
if($Value != ''){
$body .= "$Field: $Value\n";
}
}
$name = trim(htmlentities($_GET['name'],ENT_QUOTES,'utf-8'));

$email = trim(htmlentities($_GET['email'],ENT_QUOTES,'utf-8'));

$phone = trim(htmlentities($_GET['phone'],ENT_QUOTES,'utf-8'));

$messages = trim(htmlentities($_REQUEST['messages'],ENT_QUOTES,'utf-8'));


if (strlen($name) == 0 )
{
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}

if (strlen($email) == 0 )
{
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}


$to = "junior.8791@gmail.com";

$message = "Name: ".$name;

$message.="\n\nEmail: ".$email;

$message.="\n\nPhone: ".$phone;

$message .= "\n\nMessage: ".$messages;

$headers = "From: $email";

$headers .="\nReply-To: $email";

$success = mail($to, $subject, $message, $headers);


if ($success) {

    echo "<script>window.location = 'http://www.mason372.org/thankyou.html'</script>";

} else {

    echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";

}

?>

联系表格

 <form action="email.php" method="post" id="form">
            <div class="5grid">
              <div class="row">
                <div class="6u">
                  <input type="text" class="name" name="name" id="name" placeholder="Name" value="" aria-describedby="name-format" required aria-required=”true” pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+"  title="e.g.'John Doe'" required="" />

                </div>
                <div class="6u">
                  <input type="email" class="email" name="email" id="email" placeholder="Email" required="" />

                </div>
              </div>
              <div class="row">
                <div class="12u">
                  <input type="tel" class="tel" name="phone" id="phone" name="phone" type="text" placeholder="Phone Number" pattern="(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}" required />

                </div>
              </div>
              <div class="row">
                <div class="12u">
                  <textarea name="messages" id="messages" placeholder="Message"></textarea>
                </div>
              </div>
              <div class="row">
                <div class="12u">
                  <input type="submit" class="button" value="Send Message">
                  <input type="reset" class="button button-alt" value="Clear Form">

0 个答案:

没有答案