我的联系表单每天都会收到垃圾邮件。不知道为什么。这是contact-process.php来处理提交:
<?php
// configure
$from = 'webmaster@example.com';
$sendTo = 'Message from <myemail@mydomain.com>';
$subject = "Contact Form: $name";
$fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message'); // array variable name => Text to appear in the email
$human = intval($_POST['humans']);
$okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!';
$errorMessage = 'There was an error while submitting the form. Please try again later';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// let's do the sending
try
{
$emailText = "You have new message from contact form\n=============================\n";
foreach ($_POST as $key => $value) {
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
mail($sendTo, $subject, $emailText, implode("\n", $headers));
$responseArray = array('type' => 'success', 'message' => $okMessage);
header('Location: /thank-you.php');
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
}
else {
echo $responseArray['message'];
}
//Check if simple anti-bot test is correct
if(!empty($_POST['humans'])) {
// it's spam
} else {
// it's human
}
我不知道为什么会这样,我也设置了一个蜜罐。此外,电子邮件是从主机名发送的,而不是从各个电子邮件地址本身发送的。
感谢帮助人员。