我在寫一個簡單的PHP表單。對於表單中的一個字段,如果它與字段佔位符中的文本匹配,我想替換該變量的內容,因此它不會在電子郵件中發送。更改與字符串匹配的POST變量
<p>Base Colour Preference
<input type="text" name="basecolour" value="ENTER BASE COLOUR">
</p>
+
if ($basecolour == "ENTER BASE COLOUR") {
$basecolour = "No colour chosen";
}
應該改變變量,不應該嗎?而是通過電子郵件發送「ENTER BASE COLOR」的原始字符串。下面是整個代碼:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$basecolour = $_POST['basecolour'];
$highlightcolour = $_POST['highlightcolour'];
$comments = $_POST['comments'];
$header = "from <$email>";
$message = "From: $name \nBase Colour: $basecolour \nHighlight Colour: $highlightcolour \nComments: $comments";
$to = "[email protected]";
$subject ="Preorder Registration";
if ($basecolour == "ENTER BASE COLOUR") {
$basecolour = "No colour chosen";
}
if ($name == "YOUR NAME") {
echo "Please enter your name";
}
if ($email == "YOUR EMAIL") {
echo "Please enter your email address";
}
else {
mail($to, $subject, $message, $header) or die("error!");
echo "DONE";
}
?>
任何幫助最受讚賞!我還在學習:)
「我還在學習」學習如何使用輸入驗證和轉義。恕我直言,這是第一個要做的。 – rabudde