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

  • 3
    none of your inputs are named. You are setting their IDs only. Set their name as well. – dazed-and-confused Oct 27 '20 at 01:52
  • Configuring your system to work successfully with the `mail()` function is prohibitively difficult. I'd recommend using a tool like PHPMailer to send via a trusted SMTP server like GMail – Phil Oct 27 '20 at 01:52
  • I added the names but there is still no functionality. I will look into the suggestion on php mailer. thanks for the advice. – everythingEquals42 Oct 27 '20 at 02:07

1 Answers1

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>
dazed-and-confused
  • 1,293
  • 2
  • 11
  • 19