2012-09-20 3 views
0

HTML5 양식의 텍스트 영역 (아래 "메시지") 필드가 (이메일 작성에 사용 된) 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

Regex 대신 filter_var($email, FILTER_VALIDATE_EMAIL);을 사용하는 것이 좋습니다. 나는 이것이 더 구체적 일 것이라고 생각한다.

+0

좋은 지적, 팁 주셔서 감사! –

관련 문제