Why is my php form data not being submited to my email [duplicate]

与世无争的帅哥 提交于 2021-01-29 05:52:41

问题


                        <?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);
                            
                        }
                    
                      ?>

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>

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!****


回答1:


You have:

<input type="text" class="form-control form control-sm" id="name" placeholder="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>


来源:https://stackoverflow.com/questions/64547277/why-is-my-php-form-data-not-being-submited-to-my-email

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!