首页 > 解决方案 > 表单邮件安全

问题描述

我有一个基于 php 的表单邮件程序。我已经使用了很长时间了。但是,我想知道是否有可能使它更安全。有人在以下代码中看到漏洞吗?有没有什么可能的黑客可以注入一些东西的地方?我能想到的其他可能的漏洞是被认为是不安全的已弃用代码,因此通常会被其他东西取代。

<?php
$straddressee = 'info@myexample.com';
$strFrom       = '"mailer" <dictformmail@myexample.com>';
$strSubject    = 'Message';
$strReturnhtml = 'thankyou.php';
$strDelimiter  = ":\t";

if($_POST)
{
 $strMailtext = "";
 while(list($strName,$value) = each($_POST))
 {
  if(is_array($value))
  {
   foreach($value as $value_array)
   {
    $strMailtext .= $strName.$strDelimiter.$value_array."\n";
   }
  }
  else
  {
   $strMailtext .= $strName.$strDelimiter.$value."\n";
  }
 }

 if(get_magic_quotes_gpc())
 {
  $strMailtext = stripslashes($strMailtext);
 }

 mail($straddressee, $strSubject, $strMailtext, "From: ".$strFrom)
  or die("The email could not be sent.");
 header("Location: $strReturnhtml");
 exit;
}

?>
<!DOCTYPE html>
<html lang="en">
    <body>
    <p>Your message:</p>
<form action="<?php echo htmlentities("/mailer/"); ?>" method="post">

<p>Salutation:<input type="text" name="Salutation" /></p>
<p>Your Name:<input type="text" name="name" /></p>
<p>Your Email:<input type="text" name="email"  size="30"></p>
<p>Subject:<input type="text" name="subject"  size="35"></p>
<p>Your message:<textarea name="Message">message</textarea></p>
      <input type="submit" value="submit" />
</form>
</body>
</html>

标签: phpformsemailsecurity

解决方案


推荐阅读