我的联系表单发送空白的body_messages

时间:2012-10-12 12:58:44

标签: php forms dreamweaver contact

我是PHP的新手所以请耐心等待。当我按提交时,我的表单正在发送空电子邮件。任何帮助都会很棒。

这是我的表格:

    <form class="contact_form" action="kontakt.php" method="post">
        <p><input type="text" required="required" id="name" name="name" class="text_input" value="" size="22"  />
        <label for="name">Namn *</label></p>

        <p><input type="text" required="required" id="company" name="company" class="text_input" value="" size="22"  />
        <label for="company">Företag *</label></p>

        <p><input type="email" required="required" id="email" name="email" class="text_input" value="" size="22"  />
        <label for="email">Epost *</label></p>

        <p><textarea required="required" name="content" class="textarea" cols="30" rows="5"></textarea></p>

        <p><button type="submit" class="button white"><span>Skicka</span></button></p>
        <input type="hidden" value="info@web.se" name="contact_to"/>
    </form>

到目前为止,我的PHP代码是:

<?php

$name = $_POST['name'];
$company = $_POST['company'];
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$content = $_POST['content'];



$mail_to = 'info@web.se';

$subject = 'Lilla form'.$name;



$body_message = 'From: '.$name."\n";

$body_message .= 'E-mail: '.$email."\n";

$body_message .= 'Message: '.$content;



$headers = 'From: '.$email."\r\n";

$headers .= 'Reply-To: '.$email."\r\n";



$mail_status = mail($mail_to, $subject, $body_message, $headers);

?>

请帮助我,我真的被卡住了。

谢谢大家!

1 个答案:

答案 0 :(得分:2)

试试这个

 <form class="contact_form" action="kontakt.php" method="post">
    <p><input type="text" required="required" id="name" name="name" class="text_input" size="22"  />
    <label for="name">Namn *</label></p>

    <p><input type="text" required="required" id="company" name="company" class="text_input" size="22"  />
    <label for="company">Företag *</label></p>

    <p><input type="email" required="required" id="email" name="email" class="text_input"  size="22"  />
    <label for="email">Epost *</label></p>

    <p><textarea required="required" name="content" class="textarea" cols="30" rows="5"></textarea></p>

    <p><button type="submit" class="button white"><span>Skicka</span></button></p>
    <input type="hidden" value="info@web.se" name="contact_to"/>
</form>

编辑:(调试)

$name = $_POST['name'];
$company = $_POST['company'];
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$content = $_POST['content'];

echo $name.$comapny.$email.$content;exit; // check whether the values are posted successfully or not