我是 PHP 新手,无论如何都不是专家。无论如何,我正在构建一个 PHP 和 HTML 联系表单,并且在验证字段输入(trim、strip、htmlspecchars ..)的过程中搞混了。无论如何,这是我的代码,请放轻松,我是这个菜鸟。
<?php
// define variables and set to empty values
$name = $email = $web = $telephone = $pages = $completion_date = $update_option = $hosting_option = $domain_option = $text = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = test_input($_POST["name"]);
$email = test_input($_POST["email"]);
$web = test_input($_POST["web"]);
$telephone = test_input($_POST["telephone"]);
$pages = test_input($_POST["pages"]);
$completion_date = test_input($_POST["completion_date"]);
$update_option = test_input($_POST["update_option"]);
$hosting_option = test_input($_POST["hosting_option"]);
$domain_option = test_input($_POST["domain_option"]);
$text = test_input($_POST["text"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$msg = $name . "\n";
$msg = $email . "\n";
$msg = $web . "\n";
$msg = $telephone . "\n";
$msg = $pages . "\n";
$msg = $completion_date . "\n";
$msg = $update_option . "\n";
$msg = $hosting_option . "\n";
$msg = $domain_option . "\n";
$msg = $text . "\n";
$recipient = "myemail@mydomain.com";
$subject = "Contact Has Been Made..";
$mailheaders = "MIME-Version: 1.0" . "\r\n";
$mailheaders = "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$mailheaders = "From: <myemail@mydomain.com>, Reply-To: <myemail@mydomain.com>" . "\r\n";
$mailheaders = "Cc: <$email>" . "\r\n";
mail($recipient, $subject, $msg, $mailheaders);
?>