联系表单工作但有时会发送空白字段

时间:2014-01-15 16:41:52

标签: php contact-form

我有一个工作正常的联系表单,但有时会收到空白字段的电子邮件。它们可以在5分钟内完成6分钟。似乎没有一种模式。非常感谢任何帮助或见解。

这是html

<form id="form-contact" method="post" action="contact.php">
  <div class="span6 center white"><input type="text" placeholder="Name" name="contact_name" id="contact_name" /></div>
  <div class="span6 center white"><input type="email" placeholder="Email" name="contact_email" id="contact_email" /></div>
  <div class="span6 center"><textarea cols="6" rows="4" placeholder="Message" name="contact_message" id="contact_message"></textarea></div>
  <div class="span12 center"><a href="" id="contact_send" class="btn btn-large btn-icon white"><i class="icon-envelope-alt"></i>Send</a></div>
</form>

这是contact.php         

$to = 'email@email.com'; 

ini_set('SMTP', 'email@email.com');

ini_set('smtp_port', '26');
if($to) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];

    $html = "";
    $html .= "Name: " . htmlentities($name, ENT_QUOTES, "UTF-8") . "\n";
    $html .= "Email: " . htmlentities($email, ENT_QUOTES, "UTF-8") . "\n";
    $html .= "Message: " . htmlentities($message, ENT_QUOTES, "UTF-8") . "\n";


    $headers .= "From: " . $name . "<". $email .">\r\n";
    $headers .= "Reply-To: " .  $email . "\r\n";

    $html = utf8_decode($html);

    mail($to, $subject, $html, $headers);

    if ($html)
        echo 'ok';
    else
        echo 'error';

} else {
    echo "error";   
}

?>

0 个答案:

没有答案