-2

This is the HTML contact form I created and I have been trying to get the PHP code that will make it work however I am not sure the best way to handle this. I have read through other questions and answers where they use separate files I am not an expert in PHP but I can assume the two files must be linked by name this is the HTML form I have:

<section class="our-contacts slideanim" id="contact">
<h3 class="text-center slideanim">Contact Us</h3>
<p class="text-center slideanim">Got a project in mind? Shoot as an email below!</p>
<div class="container">
    <div class="row">
        <div class="col-lg-12">
            <form role="form">
                <div class="row">
                    <div class="form-group col-lg-4 slideanim">
                        <input type="text" name="name" class="form-control user-name" placeholder="Your Name" required/>
                    </div>
                    <div class="form-group col-lg-4 slideanim">
                        <input type="email" name="email" class="form-control mail" placeholder="Your Email" required/>
                    </div>
                    <div class="form-group col-lg-4 slideanim">
                        <input type="tel" class="form-control pno" placeholder="Your Phone Number" required/>
                    </div>
                    <div class="clearfix"></div>
                    <div class="form-group col-lg-12 slideanim">
                        <textarea name="message" class="form-control" rows="6" placeholder="Your Message" required/>                            </textarea>
                    </div>
                    <div class="form-group col-lg-12 slideanim">
                        <button type="submit" href="#" class="btn-outline1">Submit</button>
                    </div>
                </div>
            </form>
        </div>  
    </div>
</div>

Anthony
  • 3
  • 1
  • Read up on the form `action` attribute [here](http://stackoverflow.com/a/8395283/3097877) or [here](https://www.w3schools.com/tags/att_form_action.asp) – DiddleDot Feb 21 '17 at 23:44
  • You can use the same file to take care of sending the message, or use an additional file. If you want to use the same file you will have to add an if-statement at the top to check whether you are just loading the page or a form was submitted. You also may want to change 'as' to 'us' – RST Feb 21 '17 at 23:47

1 Answers1

0

The form tag needs to have an action and a method attribute, like this:

<form role="form" method="post" action="path/to/file.php">

The method will normally be post (you can look up the difference between post and get if you like). The action is the path to the php file that will process the data.

In the php file you can access the data through the $_POST global variable which will be an array containing each of the inputs eg $_POST['tel'] will be the telephone number field from your form.

Then you need to send the email. You can try one of the implementations in the php manual (http://php.net/manual/en/refs.remote.mail.php) or you could try using a 3rd party service like mail gun.

Peter Astbury
  • 115
  • 1
  • 1
  • 6