如何修复“通知:未定义的索引:消息中”

时间:2019-08-09 11:32:42

标签: php html

我是PHP的新手,正尝试制作一种可以通过电子邮件发送给我的表格。但是,提交时出现错误。

我在下面粘贴了HTML和PHP表格,对我能提供的任何帮助表示感谢。

            <form  style="text-align: center; border: 1px solid black;" action="" method="post" id="form">

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="title_text">TITLE</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <div>
                            <select id="title" name="title" style="margin-top: 5px;">
                                <option value="">Please select</option>
                                <option value="Mr">Mr</option>
                                <option value="Mr">Mrs</option>
                                <option value="Mr">Mx</option>
                                <option value="Mr">Ms</option>
                                <option value="Mr">Miss</option>
                                <option value="Mr">Dr</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="name_text" style="margin-top: 3px;">First Name *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <div>
                            <input type="text" id="first_name" name="first_name" style="margin-top: 5px;" required>
                        </div>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="last_text" style="margin-top: 3px;">Last Name *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <div>
                            <input type="text" id="last_name" name="last_name" style="margin-top: 5px;" required>
                        </div>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="dept_text" style="margin-top: 3px;">Department *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <div>
                            <select id="dept" name="dept" style="margin-top: 5px;">
                                <option value="">Please select</option>
                                <option value="Mr">Mr</option>
                                <option value="Mr">Mrs</option>
                                <option value="Mr">Mx</option>
                                <option value="Mr">Ms</option>
                                <option value="Mr">Miss</option>
                                <option value="Mr">Dr</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="job" style="margin-top: 3px;">Job Title *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <div>
                            <input type="text" id="job" name="job" style="margin-top: 5px;" required>
                        </div>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="start" style="margin-top: 3px;">Start Date *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <div>
                            <input type="date" id="start" name="start" style="margin-top: 5px;" required>
                        </div>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="manager" style="margin-top: 3px;">Manager *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <select id="manager" name="manager" style="margin-top: 5px;" required>
                            <option value="">Please select</option>
                            <option value="Mr">Mr</option>
                            <option value="Mr">Mrs</option>
                            <option value="Mr">Mx</option>
                            <option value="Mr">Ms</option>
                            <option value="Mr">Miss</option>
                            <option value="Mr">Dr</option>
                        </select>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="location" style="margin-top: 3px;">Location *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <select id="location" name="location" style="margin-top: 5px;" required>
                            <option value="">Please select</option>
                            <option value="Mr">Mr</option>
                            <option value="Mr">Mrs</option>
                            <option value="Mr">Mx</option>
                            <option value="Mr">Ms</option>
                            <option value="Mr">Miss</option>
                            <option value="Mr">Dr</option>
                        </select>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="nwc" style="margin-top: 3px;">Now We Comply *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <select id="nwc" name="nwc" style="margin-top: 5px;" required>
                            <option value="">Please select</option>
                            <option value="Mr">Mr</option>
                            <option value="Mr">Mrs</option>
                        </select>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="vdq" style="margin-top: 3px;">VQD? Which instance? *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <div>
                            <input type="text" id="vdq" name="vdq" style="margin-top: 8px;" required>
                        </div>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="phone" style="margin-top: 3px;">Phone Extention *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <select id="phone" name="phone" style="margin-top: 5px;" required>
                            <option value="">Please select</option>
                            <option value="Mr">Yes</option>
                            <option value="Mr">No</option>
                        </select>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="hardware" style="margin-top: 3px;">IT Hardware *</label> //come back to this
                        </div>
                    </div>

                    <div class="col-md-8">
                        <div class="checkbox">
                            <label><input type="checkbox" if="keyboard" value="keyboard">Keyboard</label>
                        </div>
                        <div class="checkbox">
                            <label><input type="checkbox" id="mouse" value="mouse">Mouse</label>
                        </div>
                        <div class="checkbox disabled">
                            <label><input type="checkbox" id="laptop" value="laptop">Laptop</label>
                        </div>
                        <div class="checkbox disabled">
                            <label><input type="checkbox" id="desktop" value="desktop">Desktop</label>
                        </div>
                        <div class="checkbox disabled">
                            <label><input type="checkbox" id="monitor" value="monitor">Monitor</label>
                        </div>
                        <div class="checkbox disabled">
                            <label><input type="checkbox" id="docking_station" value="docking_station">Docking Station</label>
                        </div>
                        <div class="checkbox disabled">
                            <label><input type="checkbox" id="case" value="case">Laptop Case</label>
                        </div>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="login" style="margin-top: 3px;">AD log in *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <div>
                            <input type="text" id="login" name="login" style="margin-top: 5px;" required>
                        </div>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="password" style="margin-top: 3px;">Password *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <div>
                            <input type="password" id="password" name="password" style="margin-top: 5px;" required>
                        </div>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="email" style="margin-top: 3px;">Email Address(es) *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <div>
                            <input type="text" id="email" name="email" style="margin-top: 5px;" required>
                        </div>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="disgroup" style="margin-top: 3px;">Distribution Groups *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <div>
                            <input type="text" id="disgroup" name="disgroup" style="margin-top: 5px;" required>
                        </div>
                    </div>
                </div>

                <div class="row spacing-top">
                    <div class="col-md-4">
                        <div>
                            <label id="access" style="margin-top: 3px;">Drive & Folder Access *</label>
                        </div>
                    </div>

                    <div class="col-md-8">
                        <div>
                            <input type="text" id="access" name="access" style="margin-top: 5px;" required>
                        </div>
                    </div>
                </div>

                <input type="submit" name="submit" value="Submit">

            </form>

        </div>
    </div>

</body>
</html>

<?php
if(isset($_POST['submit'])){
    $to = "MY EMAIL"; // this is your Email address
    $from = "ANOTHER EMAIL"; // this is the sender's Email address
    $title = $_POST['title'];
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $dept = $_POST['dept'];
    $job = $_POST['job'];
    $start = $_POST['start'];
    $manager = $_POST['manager'];
    $location = $_POST['location'];
    $nwc = $_POST['nwc'];
    $vdq = $_POST['vdq'];
    $phone = $_POST['phone'];

    $login = $_POST['login'];
    $password = $_POST['password'];
    $email = $_POST['email'];
    $disgroup = $_POST['disgroup'];
    $access = $_POST['access'];
    $subject = "New Starter";
    $message = "Here is the new starter details" . "\n\n" . $title . "\n" . $first_name . "\n" .
                $last_name . "\n" . $dept . "\n" . $job . "\n" . $start . "\n" . $manager . "\n" .
                $location . "\n" . $nwc . "\n" . $vdq . "\n" . $phone. $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    }
?>

这是我单击提交时遇到的错误“ Notice:Undefined index:/ 355上/storage/ssd1/948/10446948/public_html/index.php中的消息”

1 个答案:

答案 0 :(得分:0)

$ _ POST ['message']没有价值/缺失。您可能需要在html中插入才能获取它们。这就是为什么它向您发出未定义索引的原因。

<input type="textarea" name="message">

in your php code:

$user_message = $_POST['message'];

in your last line of $message put .$user_message 

希望这会有所帮助,如果您的邮件功能不起作用,则可能需要配置邮件服务器才能在php代码中启用发送电子邮件功能。祝一切顺利!