-1

So here is the problem I am facing. I have created a pretty simple web form:

    <form  method="post"  action="#">
                  <div  class="field"> <label  for="name">Name</label>
                    <input  name="name"  id="name"  type="text"> </div>
                  <div  class="field"> <label  for="email">Email</label> <input

                       name="email"  id="email"  type="email"> </div>
                  <div  class="field"> <label  for="message">Message</label> <textarea

 name="message"  id="message"  rows="4"></textarea> </div>
                  <ul  class="actions">
                    <li><input  value="Send Message"  type="submit"></li>
                  </ul>
                </form>

I need to know how I can use this form to send data inputed by the user to my email address admin@nue-tech.uk I am aware this can be done in PHP but am unsure how to approach this as I am unfamilliar with PHP. If someone could please point me in the right direction as to how this can be done, and also where I should place the PHP file relative to this, that'd be awesome!

  • This is also somehting you would find loads of tutorials for if you tried a site called: "Google" (http://google.com). Just search for "php email form" – M. Eriksson Jan 17 '16 at 13:11

1 Answers1

0

You could copy the code below and paste it in your HTML file below your html. In your html you set the action attribute empty. Don't forget to change your file extension to .php

<?php 
if(isset($_POST['submit'])){
$to = "admin@nue-tech.uk";
$from = $_POST['email'];
$name = $_POST['name'];
$subject = "Blablabla"; //Write whatever you want here
$message = $name . "wrote the following:" . "\n\n" . $_POST['message'];

$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
header('location: thank-you.html'); //redirects the user to another page if the mail was send succesfully
} else {
header('location: contact.html'); //if it was not send succesfully it redirects to the contact page again
exit(0);
}
?>

In

header('location: contact.html');

you could also use

echo "Something went wrong. Try again later" 

or something simular. I would highly recommend you search and learn on W3Cschools or at php.net.

YentlPauwels
  • 38
  • 2
  • 11