Search code examples
phphtmlmessagesendmessage

Message Send Form


How to connect "Message send form" in html file to php so that all Message typed in given form on website are sent directly to my gmail address?

 <section id="contact">
      <div class="container">
           <div class="row">

                <div class="col-md-6 col-sm-12">
                     <form id="contact-form" role="form" action="action.php" method="post">
                          <div class="section-title">
                               <h2>Contact us <small>We are open to talk. We work for you. Let us talk!</small></h2>
                          </div>

                          <div class="col-md-12 col-sm-12">
                               <input type="text" id="text" class="form-control" placeholder="Enter full name" name="text" required="">
                
                               <input type="email" id="email" class="form-control" placeholder="Enter email address" name="email" required="">

                               <textarea id="message" class="form-control" rows="6" placeholder="Tell us about your message" name="message" required=""></textarea>
                          </div>

                          <div class="col-md-4 col-sm-12">
                               <input type="submit" id="submit" class="form-control" name="send message" value="Send Message">
                          </div>

                     </form>
                </div>

                <div class="col-md-6 col-sm-12">
                     <div class="contact-image">
                          <img src="images/kingdom.jpg" class="img-responsive" alt="Kingdom Education Logo">
                     </div>
                </div>

           </div>
      </div>
 </section>

Solution

  • I think you know that your attribute action="action.php" brings the form data and the user to the action.php page in the same folder, so, just put there (also with some writing like 'Thank you for contacting us') this:

    mail('YOUR EMAIL', _POST['text'].' ('._POST['email'.')', _POST['message']);
    

    So your server will send you an email with the apache mail in which there will be the person who contacted you in the object and the message as text of the mail