PHP电子邮件表单发送空白邮件

时间:2013-07-06 06:05:35

标签: php html email

我在联系我表单中添加了一个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! :)";
    }

1 个答案:

答案 0 :(得分:2)

您需要返回您的函数中的值。

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