使用PHP发送电子邮件的HTML Web表单不会发送所有字段

时间:2013-07-19 21:53:27

标签: php html webforms

我需要为用户创建一个webform来输入他们的信息,从下拉菜单中选择一些选项,并包含一个附件。提交此表单时,应生成并发送电子邮件给我。

所有字段都有效(其中,它们显示在我收到的电子邮件中)附件(我没有IDEA如何使附件正常工作)。我只有一个HTML介绍当然,从来没有学过PHP,似乎没有任何谷歌搜索让我得到我想要的答案,而没有完全重写我的所有代码。我希望这是一个快速修复,我只是忽略了。

这是我的HTML代码:

<!DOCTYPE html>
 <html lang="en">
 <head>
    <meta charset="utf-8" />
    <title></title>
 </head>

<body>
    <div id="container">
        <header>
        </header>
    <div id="maincontent">
        <script>
            $(document).ready(function() {
                $(':text:first').focus();
            });
        </script>

        <div id="form_container">

        <form action="sendemail.php" method="post" enctype="multipart/form-data">
        <ul id="emailform">
            <li>
                <label for="ef_title">Title: </label>
                <span class="fieldbox"><input type="text" name="ef_title" required="required"></span>
            </li>
            <li>
                <label for="ef_users">Users Impacted: </label>
                <span class="fieldbox"><input type="text" name="ef_users" required="required"></span>
            </li>
            <li>
                <label for="ef_datetime">Date/Time: </label>
                <span class="fieldbox"><input type="datetime" name="ef_datetime" required="required"></span>
            </li>
            <li>
                <label for="ef_priority">Priority: </label>
                <p>

                    <select name="selectpri" required="required">
                      <option value="">Select...</option>
                      <option value="1">1</option>
                      <option value="2">2</option>
                      <option value="3">3</option>
                    </select>
                </p>
                <!-- <span class="fieldbox"><input type="datetime" name="ef_datetime" required="required"></span> -->
            </li>
            <li>
                <label for="ef_blocking">Blocking: </label>
                <p>

                    <select name="selectblock" required="required">
                      <option value="">Select...</option>
                      <option value="yes">Yes</option>
                      <option value="no">No</option>

                    </select>
                </p>
            </li>

            <li>
                <label for="ef_url">URL of Observed Behavior: </label>
                <span class="fieldbox"><input type="url" name="ef_url" required="required"></span>
            </li>

            <li>
                <label for="ef_desc">Description of Behavior: </label>
                <span class="msgbox"><textarea class="area" name="ef_desc" required="required"></textarea></span>
            </li>

            <li>
                <label for="ef_results">Expected Results: </label>
                <span class="msgbox"><textarea class="area" name="ef_results" required="required"></textarea></span>
            </li>

            <li>
                <label for="ef_repro">Repro Steps: </label>
                <span class="msgbox"><textarea class="area" name="ef_repro" required="required"></textarea></span>
            </li>
            <li>
                <label for='uploaded_file'>Select A File To Upload:</label>
                <input type="file" name="file" id="file">

            </li>


        </ul>
    <input id="sendbutton" type="submit" value="Send">
    <input id="clearbutton" type="reset" value="Clear">
    <br /><br />
</form>
    </div>




    </div>
    <footer>
    </footer>
    </div>
</body>
</html>

这是我的PHP代码:

<?php


$field_title = $_POST['ef_title'];
$field_users = $_POST['ef_users'];
$field_datetime = $_POST['ef_datetime'];
$field_priority = $_POST['selectpri'];
$field_blocking = $_POST['selectblock'];
$field_url = $_POST['ef_url'];
$field_desc= $_POST['ef_desc'];
$field_results = $_POST['ef_results'];
$field_repro = $_POST['ef_repro'];
$field_attach = $_POST['file'];




$mail_to = 'katcole@uw.edu';
$subject = $field_title;

$body_message .= 'Title: '.$field_title."\n";
$body_message .= 'Users: '.$field_users."\n";
$body_message .= 'Date/Time: '.$field_datetime."\n";
$body_message .= 'Priority: '.$field_priority."\n";
$body_message .= 'Blocking: '.$field_blocking."\n";
$body_message .= 'URL of Observed Behavior: '.$field_url."\n";
$body_message .= 'Description of Behavior: '.$field_desc."\n";
$body_message .= 'Expected Results: '.$field_results."\n";
$body_message .= 'Repro Steps: '.$field_repro."\n";
$body_message .= 'Attachments: '.$field_attach."\n";




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

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly.');
        window.location = 'index.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to v-jacoca@microsoft.com');
        window.location = 'index.html';
    </script>
<?php
}
?>

感谢您对此事的帮助! :)

3 个答案:

答案 0 :(得分:0)

改变这个:

$field_priority = $_POST['ef_priority'];
$field_blocking = $_POST['ef_blocking'];

到此:

$field_priority = $_POST['selectpri'];
$field_blocking = $_POST['selectblock'];

答案 1 :(得分:0)

在您定义的代码中

$field_priority = $_POST['ef_priority'];
$field_blocking = $_POST['ef_blocking'];

没有表单元素名称ef_priorityef_blocking更改表单元素名称或更改代码以匹配名称

答案 2 :(得分:0)

更改这些:

<select name="selectpri" required="required">
<select name="selectblock" required="required">

到这些:

<select name="ef_priority" required="required">
<select name="ef_blocking" required="required">

此外,您需要从HTML表单中获取该文件,请参阅以下链接:

http://phpmaster.com/file-uploads-with-php/