2012-09-20 56 views
0

需要幫助理解爲什麼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&apos;ordre <br /> g&eacute;n&eacute;ral seulement. Veuillez utiliser demande formulaire situ&eacute; <br /> sur la page Service pour commencer.</p> 

         <label><span>Nom</span> 
         <input class="inputcontact" name="name" type="text" /></label> 
         <label><span>Courrier <br />&Eacute;lectronique</span> 
         <input class="inputcontact" name="email" type="text" /></label> 
         <label><span>T&eacute;l&eacute;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(); 
} 
?> 

回答

3
$messaage = check_input($_POST["message"]); 

Message:$message. 

是確定或拼寫錯誤?

+0

DOH !!!!我沒有注意到樹林裏的森林。謝謝MrSil –

0

您的變量名稱$message在第9行有一個錯字(您寫下了$messaage)。

0

我建議您使用filter_var($email, FILTER_VALIDATE_EMAIL);而不是您的正則表達式。我認爲這將更具體

+0

好點,謝謝你的提示! –