0

需要帮助来理解为什么 HTML5 表单中的 textarea(下面的“消息”)字段没有从 PHP 代码(用于创建电子邮件)中获取。

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  = "xxxxxx@gmail.com";

/* 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();
}
?>
4

3 回答 3

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

Message:$message.

没问题还是拼写错误?

于 2012-09-20T15:34:19.080 回答
0

您在第 9 行的变量名中有错字$message(您写了$messaage)。

于 2012-09-20T15:38:03.893 回答
0

我建议您使用filter_var($email, FILTER_VALIDATE_EMAIL);而不是您的正则表达式。我认为这会更具体

于 2012-09-20T15:46:40.047 回答