所以我在网上得到了这个“联系我们”表单的 PHP 代码(我自己没有编写 PHP 代码),但它包含了我的完整电子邮件地址。以下表格是否使我的电子邮件免受垃圾邮件发送者的侵害?
contact.php 文件(真实邮箱已被 MYEMAIL@COMPANY.COM 取代):
<?php
// Contact Form
// Get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "MYEMAIL@COMPANY.COM";
$Subject = "A User Has Contacted You";
$Name = Trim(stripslashes($_POST['Name']));
$Message = Trim(stripslashes($_POST['Message']));
// Validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (Trim($Name)=="") $validationOK=false;
if (Trim($Message)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// Prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// Send E-Mail
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// Redirect to Success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=success.htm\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
html片段:
<form method="POST" action="contact.php">
...
</form>
我读过 PHP 中包含的电子邮件地址对于爬虫来说是完全安全的,因为它都是服务器端的(假设您的服务器/站点是安全的)。不知道这是否属实,网上搜了这么多信息,我找不到确切的答案。如果有人可以确认此代码是否可以安全使用,那就太好了,谢谢!