繁体   English   中英

提交联系表格数据

[英]Submitting contact form data

联系表单有几个文本字段和几个下拉菜单,可以选择多个值。 问题是如何通过电子邮件发送这些值? 字符串类型的文本值(一次一个单词)可以正常发送。 但是如何发送包含多个值的数组呢? 如何使用 $_POST 方法收集它们并将它们放入信中?

形式:

<section class="post-content-area pt-20">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 posts-list">
                <div class="card card-signin my-5">
                    <div class="card-body">
                        <h5 class="card-title text-center" style="font-size: 26px">Test contact form</h5>
                        <form method="post" action="email-script.php" enctype="multipart/form-data" id="emailForm"> 
                            <div class="form-group">
                                <input type="text" name="name" id="name" class="form-control" placeholder="Name" >
                                <div id="nameError" style="color: red;font-size: 14px;display: none">nameError</div>
                            </div>
                            <div class="form-group">
                                <input type="text" name="surname" id="surname" class="form-control" placeholder="Surame" >
                                <div id="nameError" style="color: red;font-size: 14px;display: none">nameError</div>
                            </div>
                            <div class="form-group">
                                <input type="text" name="phone" id="phone" class="form-control"  placeholder="Phone" >
                                <div id="subjectError" style="color: red;font-size: 14px;display: none">subjectError</div>
                            </div>
    <div class="form-group">
     <label>First Level Category</label><br />
     <select id="first_level" name="first_level[]" multiple class="form-control">
     <?php
     foreach($result as $row)
     {
      echo '<option value="'.$row["first_level_category_id"].'">'.$row["first_level_category_name"].'</option>';
     }
     ?>
     </select>
    </div>
    <div class="form-group">
     <label>Second Level Category</label><br />
     <select id="second_level" name="second_level[]" multiple class="form-control">
 
     </select>
    </div>
    <div class="form-group">
     <label>Third Level Category</label><br />
     <select id="third_level" name="third_level[]" multiple class="form-control">
 
     </select>
    </div>
        <div class="form-group">
                                <input type="file" name="attachment" id="attachment" class="form-control">
                                <div id="attachmentError" style="color: red;font-size: 14px;display: none">attachmentError</div>
                            </div>
                            <div class="submit">
                                <center><input type="submit" name="submit" onclick="return validateEmailSendForm();" class="btn btn-success" value="SUBMIT"></center>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

电子邮件脚本: https ://pastebin.com/3SR67MUP

如何通过电子邮件发送它们有多种方法。

最简单的方法是将它们放在您的表单操作页面上并使用 php mail() 函数发送它们。

为了使电子邮件看起来更好,您可以创建一个 HTML 电子邮件模板文件。

然后使用 file_get_contents() 获取文件数据,并使用 str_replace 函数使用收集的数据重置字符串,并将数据放入您的邮件函数中。

希望能帮助到你!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM