我正在尝试清理应该是简单的电子邮件脚本的输出,但它只输出一个空白页面。这是脚本:
<?php
define("EMAIL", "info@silentpost.net");
if(isset($_POST['submit'])) {
//include validation class
include('./support/validate.class.php');
//assign post data to variables
$_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$_POST['email'] = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$message = trim($_POST['message']);
//start validating our form
$v = new validate();
$v->validateStr($name, "name", 3, 75);
$v->validateEmail($email, "email");
$v->validateStr($message, "message", 5, 1000);
if(!$v->hasErrors()) {
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "email from silentpost.net website!";
$email_to = EMAIL;
$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n\n";
$emailMessage .= $message;
@mail($email_to, $subject ,$emailMessage ,$header );
} else {
//set the number of errors message
$message_text = $v->errorNumMessage();
//store the errors list in a variable
$errors = $v->displayErrors();
//get the individual error messages
$nameErr = $v->getError("name");
$emailErr = $v->getError("email");
$messageErr = $v->getError("message");
}//end error check
}// end isset
?>
如果我省略以下代码,脚本将运行良好:
$_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$_POST['email'] = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
如果有必要,我会包含该类,但我不认为这是类的问题,因为正确删除filter_var行输出。
任何帮助都将不胜感激。
答案 0 :(得分:1)
我会做两件事:
一个。确保你运行PHP&gt; = 5.2(filter_var函数的最小值)。
B中。将error_reporting(E_ALL);
添加到脚本顶部,这样可以查看导致空白页面的错误。
答案 1 :(得分:0)
脚本似乎没有任何问题。确切的问题是什么?如果您进行消毒或者没有输出任何输出,您的脚本是否不发送电子邮件?如果是后者,那么我认为你的脚本不会产生任何输出。
尝试在清理之前和之后回显您的内容,看看它们是否有所不同:
echo 'BEFORE<br>';
echo $_POST['name'] . '<br>';
echo $_POST['email'] . '<br>';
echo $_POST['message'] . '<br>';
$_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$_POST['email'] = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
echo 'AFTER<br>';
echo $_POST['name'] . '<br>';
echo $_POST['email'] . '<br>';
echo $_POST['message'] . '<br>';