0

我在我的联系我表单中添加了一个 clean() 函数来去除特殊字符,出于某种原因,它只是发送空白消息,没有主题,什么都没有。如果我从字符串中删除该函数,那么它就可以工作。

这是表格的一部分:

function clean($string) {
preg_replace('/[^a-zA-Z0-9\s]/', '', strip_tags(html_entity_decode($string)));
}

if (isset($_REQUEST['email']))
  {//if "email" is filled out, proceed

  //check if the email address is invalid
  $mailcheck = spamcheck($_REQUEST['email']);
  if ($mailcheck==FALSE)
    {
    echo "Invalid input. Please <a href='http://pattersoncode.ca/index.php?a=help'>try again</a>";
    }
  else
    {//send email
    $email = $_REQUEST['email'] ;
    $product = clean($_REQUEST['product']);
    $message = clean($_REQUEST['message']);
    mail("support@pattersoncode.ca", "Subject: $product",
    $message, "From: $email" );
    echo "I'll be in contact shortly, thanks! :)";
    }
4

1 回答 1

2

您需要从函数中返回一个值。

function clean($string) {
return preg_replace('/[^a-zA-Z0-9\s]/', '', strip_tags(html_entity_decode($string)));
}
于 2013-07-06T06:12:39.203 回答