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

时间:2022-10-16 11:13:15

I need to make a webform for users to input their information, choose a few selections from dropdown menus, and include an attachment. When submitting this form, it should generate and send an email to me.

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

All of the fields work (in that, they show up in the email I receive) the attachment (I have NO IDEA how to get attachments working). I have only had an intro to HTML course and never learned PHP, and it seems that no amount of googling is getting me the answer I want without completely rewriting all of my code. I'm hoping it's a quick fix, something I'm just overlooking.

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

Here is my HTML code:

这是我的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>

And here is my PHP code:

这是我的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
}
?>

Thank you for your help in this matter! :)

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

3 个解决方案

#1


0  

change this:

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

to this:

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

#2


0  

in your code you defined:

在您定义的代码中:

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

There is no form element name ef_priority and ef_blocking either change form element names or change your code to match the names

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

#3


0  

Change these:

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

to these:

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

Also, you need to get the file from the HTML form please see this link below:

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

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

#1


0  

change this:

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

to this:

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

#2


0  

in your code you defined:

在您定义的代码中:

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

There is no form element name ef_priority and ef_blocking either change form element names or change your code to match the names

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

#3


0  

Change these:

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

to these:

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

Also, you need to get the file from the HTML form please see this link below:

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

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