目前,我们收到了大量垃圾邮件。我刚刚添加了以下行:
if ($field_budget == "" || $field_timeline == "" || $field_email == "" || $field_name == "") {
echo "Please fill out all required form details, thank you!";
} else {
这帮助了几个星期,但现在垃圾邮件发送者又回来了。什么是改进我的表单的简单、优雅的方法(下面的完整代码)?
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_website = $_POST['cf_website'];
$field_company = $_POST['cf_company'];
$field_budget = $_POST['cf_budget'];
$field_custombudget = $_POST['cf_custombudget'];
$field_timeline = $_POST['cf_timeline'];
$field_message = $_POST['cf_message'];
$mail_to = 'sean@seanduran.com';
$subject = 'Message from a site visitor, '.$field_name;
$body_message = 'Name: '.$field_name."\n";
$body_message .= 'e-mail: '.$field_email."\n";
$body_message .= 'Website: '.$field_website."\n";
$body_message .= 'Company: '.$field_company."\n";
$body_message .= 'Budget: '.$field_budget."\n";
$body_message .= 'Custom Budget: '.$field_custombudget."\n";
$body_message .= 'Timeline: '.$field_timeline."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
if ($field_budget == "" || $field_timeline == "" || $field_email == "" || $field_name == "") {
echo "Please fill out all required form details, thank you!";
} else {
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'http://seanduran.com';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to sean@seanduran.com');
window.location = 'http://seanduran.com';
</script>
<?php
}
}
?>