为什么我的php表单数据未提交到我的电子邮件 [英] Why is my php form data not being submited to my email

查看:43
本文介绍了为什么我的php表单数据未提交到我的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

                        <?php 
                        
                        if (isset ($_POST['contact-form'])) {
                            $name = trim($_POST['name']);
                            $email = trim($_POST['email']);
                            $msg = $_POST['message'];
                    
                    // add the recipient email to a variable
                        $to = "myemail@gmail.com";
                    //create a subject
                        $subject = "$name sent you a message about a qoute";
                    //construct the message
                        $message = "Name: $name\r\n";
                        $message .= "Email: $email\r\n";
                        $message .= "Message: $name\r\n$msg";
                        $message = wordwrap($message,72);
                      //heading and info  
                        $headers = "MIME-Version: 1.0\r\n";
                        $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
                        $headers .= "From: $name <$email>\r\n";
                        $headers .= "X-Priority: 1\r\n";
                        $headers .= "X-MSMail-Priority: High\r\n\r\n";
                    //send email
                        mail($to, $subject, $message, $headers);
                            
                        }
                    
                      ?>

上面的代码是位于.php文件内部的php代码,而php文件中的html如下:

The above code is the php code located inside of a .php file with the html in the php file as follows:

                        <form method="post" action="" id="estimate-form">
                      <div class="form-group">
                      <input type="text" class="form-control form control-sm" id="name" placeholder="Name">
                      <div class="form-group">
                      <input type="email" class="form-control form control-sm" id="email" placeholder="Email">
                    
                        <div class="form-group">
                            <textarea type="textarea" class="form-control form control-lg" id="message" placeholder="Message"></textarea>
                      </div>
                           </div>
                          </div>
                          </div>
                      <input type="submit" name="contact-form" value="submit" class="btn btn-outline-light btn-block" style="margin-top:-10px;">
                          </div>
                        </div>
                    </form>

我遇到的问题是,提交后我没有收到电子邮件,因此我不知道该如何进行操作.是我犯了一个错误还是遗漏了一些东西? 注意:我已编辑了电子邮件,但在我的实际代码中myemail =为保密而留给我的实际电子邮件地址! ****

The issue I am having is that Upon submit I am not receiving an email and I can not figure out how to make this operational. Did I make a mistake or leave something out? NOTE: I edited my email out but in my actual code myemail = my actual email address that I left out for privacy!****

推荐答案

您拥有:

<输入类型=文本"class ="form-control form control-sm";id =名称"占位符=名称">

它和您的其他输入字段需要设置 name 属性:

It and your other input fields needs the name attribute to be set:

<input name="name" type="text" class="form-control form control-sm" id="name" placeholder="Name">

<input name="email" type="text" class="form-control form control-sm" id="name" placeholder="Name">

<textarea name="message" type="textarea" class="form-control form control-lg" id="message" placeholder="Message"></textarea>

这篇关于为什么我的php表单数据未提交到我的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆