需要幫助理解爲什麼HTML5表單中的textarea(下面的「message」)字段沒有從PHP代碼(用於創建電子郵件)中獲取。在PHP中提取HTML表單TextArea
HTML代碼(法國):
<form method="post" action="contact.php">
<fieldset>
<p class="tight" style="font-size: 10pt; text-align: center;" >Message pour des demandes de renseignements d'ordre <br /> général seulement. Veuillez utiliser demande formulaire situé <br /> sur la page Service pour commencer.</p>
<label><span>Nom</span>
<input class="inputcontact" name="name" type="text" /></label>
<label><span>Courrier <br />Électronique</span>
<input class="inputcontact" name="email" type="text" /></label>
<label><span>Téléphone</span>
<input class="inputcontact" name="telephone" type="text" /></label><br />
<label class="labelleft" for="message"> MESSAGE
<textarea name="message" rows="8" cols="45"> </textarea></label>
</fieldset>
<input class="submit" type="submit" value="ENVOYER" />
</form>
PHP代碼(contact.php):
<?php
/* Set e-mail recipient */
$myemail = "[email protected]";
/* Check all form inputs using check_input function */
$yourname = check_input($_POST['name']);
$email = check_input($_POST['email']);
$telephone = check_input($_POST['telephone']);
$messaage = check_input($_POST["message"]);
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$subject ="Comment received from website";
$content = "Hello!
The contact form from the website has been submitted by:
Name: $yourname
E-mail: $email
Telephone: $telephone
Message:$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $content);
/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
DOH !!!!我沒有注意到樹林裏的森林。謝謝MrSil –