6

我是 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);

?>

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

谢谢你们!

4

1 回答 1

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
于 2012-10-12T13:08:59.507 回答