任何人都可以看到这两个文件有什么问题吗?当我点击提交时,它只是将我重定向到一个空白页面,我从表单中得不到任何反馈,更不用说电子邮件。
HTML代码
<form action="../script/form14.php" method="POST" >
<h1>KittyBoo</h1>
<p>Beställ kattmat online - alltid laktos- och glutenfri</p><fieldset class="formular">
<legend>1. Välj produkt</legend>
<ul>
<li>
<input type="checkbox" name="Kitty Extra Small" value="Kitty Extra Small"> <li> Kitty Extra Small: 90 kr
<br></li>
<li>
<input type="checkbox" name="Kitty Small" value="Kitty Small"> <li> Kitty Small: 140 kr
<br></li>
<li>
<input type="checkbox" name="Kitty Medium" value="Kitty Medium"> <li> Kitty Medium: 180 kr
<br></li>
<li>
<input type="checkbox" name="Kitty Large" value="Kitty Large"> <li> Kitty Large: 210 kr
<br></li>
<li>
<input type="checkbox" name="Kitty Extra Large" value="Kitty Extra Large"> <li> Kitty Extra Large: 240 kr<br></li>
</ul>
</fieldset>
<fieldset class="formular">
<legend>2. Dina uppgifter</legend>
<label for="namn"> För- och efternamn:</label><br>
<input type="text" id="namn" name="from" required><br>
<label for="email">Epost:</label><br>
<input type="text" id="email" name="email" required><br>
<label for="emailconfirm">Konfirmera Epost:</label>
<input type="text" id="emailconfirm" name="emailconfirm" required>
<label for="adress">Adress:</label>
<input type="text" id="adress" name="adress" required>
<label for="postnummer">Postnummer:</label>
<input type="text" id="postnummer" name="postnummer" required>
<label for="stad">Stad:</label>
<input type="text" id="stad" name="stad" required>
<label for="land">Land:</label>
<select id="land" name="Land">
<option> Sverige</option>
<option> Finland</option>
<option> Norge</option>
<option> Danmark</option>
<option> Island</option>
</select>
</fieldset>
<fieldset class="formular">
<legend>3. Leverans</legend>
<label for="date">Välj datum för leverans:</label>
<input type="date" id="date" name="date" required/>
<p>Leveranssätt:</p>
<ul>
<li>
<input type="radio" name="radAnswer" required value="Posten"> <a> Posten</a>
<input type="radio" name="radAnswer" required value="DHL"> <a> DHL</a>
<input type="radio" name="radAnswer" required value="FedEx"> <a> FedEx</a>
</li>
</ul>
<p>Välj färg på din KittyBoo:</p>
<input type="radio" name="radAnswer" value="bla"> <a> Blå</a>
<input type="radio" name="radAnswer" value="rosa"> <a> Rosa</a>
<p>Övriga önskemål kring din leverans:</p>
<textarea name="subject" id="ovrig" rows="3" cols="30" maxlength="300" required> Max 300 ord</textarea>
</fieldset>
<input type="submit" value="skicka">
</form>
PHP脚本
<?php
function spamcheck($field)
{
// Sanitize e-mail address
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
// Validate e-mail address
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
?>
<?php
// display form if user has not clicked submit
if (!isset($_POST["submit"]))
{
?>
<?php
}
else
// the user has submitted the form
{
// Check if the "from" input field is filled out
if (isset($_POST["email"]))
{
// Check if "from" email address is valid
$mailcheck = spamcheck($_POST["email"]);
if ($mailcheck==FALSE)
{
echo "Invalid input";
}
else
{
$from = $_POST["from"]; // sender
$subject = $_POST["subject"];
$email = $_POST["email"];
function build_message($request_input){if(!isset($message_output))
{$message_output ="";}if(!is_array($request_input))
{$message_output = $request_input;}
else{foreach($request_input as $key => $value)
{if(!empty($value)){if(!is_numeric($key))
{$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}
else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
$message = build_message($_REQUEST);
// message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// send mail
mail("helenaevaschroder@gmail.com",$subject,$message, "From: $from\n");
echo "Tillbakaack för ditt meddelande";
echo "<p><a href=http://www.sh.se>Tillbaka till sidan</a></p>";
}
}
}
?>
服务器已设置为PHP。
如果有任何帮助,您可以在此处查看表单:http://student.mtstudent.se/~sh14hf2407/pages/formular.html
答案 0 :(得分:1)
您的PHP条件if (!isset($_POST["submit"])) { ... }
始终为FALSE,因为您的html表单中不存在$_POST['submit']
。您创建了一个元素<input type="submit" value="skicka">
,但$_POST['submit']
表示&#34; 名称属性提交的元素&#34;。所以替换:
<input type="submit" value="skicka">
通过
<input type="submit" name="submit" value="skicka">
此问题将得到解决。
答案 1 :(得分:0)
更改
<input type="submit" value="skicka">
进入
<input type="submit" name="submit" value="skicka">