-3

I am using a website template that comes with a good looking html form built in. The problem is that it is not setup 100% nor working.

            <div class="row">
            <div class="col-md-offset-1 col-md-10">

            <form class="form-horizontal" role="form">
              <div class="form-group">
                <div class="col-md-offset-2 col-md-8">
                  <input type="text" class="form-control" id="inputName" placeholder="Name">
                </div>
              </div>
              <div class="form-group">
                <div class="col-md-offset-2 col-md-8">
                  <input type="email" class="form-control" id="inputEmail" placeholder="Email">
                </div>
              </div>
              <div class="form-group">
                <div class="col-md-offset-2 col-md-8">
                  <input type="text" class="form-control" id="inputSubject" placeholder="Subject">
                </div>
              </div>
              <div class="form-group">
                <div class="col-md-offset-2 col-md-8">
                  <textarea name="message" class="form-control" rows="3" placeholder="Message"></textarea>
                </div>
              </div>
              <div class="form-group">
                <div class="col-md-offset-2 col-md-8">
                 <button type="button" class="btn btn-theme btn-lg btn-block">Send message</button>
                </div>
              </div>
            </form>

            </div>

I would like that to send an email to a certain address. Do I need a separate php file?

Thanks, James

chipyzs
  • 17
  • 6
  • You really need to learn the basics of PHP before you go any further. – Quentin Mar 01 '15 at 17:22
  • 1
    Teaching you the basics is a job for an introductory tutorial, not for Stackoverflow. It isn't working because you haven't written any PHP code. – Quentin Mar 01 '15 at 17:27

2 Answers2

-1

inside your form tag add

action="mailto:emailadress@gmail.com"

<form action="mailto:emailadress@gmail.com"/>
AtanuCSE
  • 8,832
  • 14
  • 74
  • 112
Developer
  • 130
  • 13
-1

Your button should be:

<button type="submit" class="">Send message</button>

*Notice the type="submit"


EDIT:

For getting it to work just create a new PHP document called "sendemail.php" with this code:

<?php
$to      = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

Now your action in your form should be:

<form action="sendemail.php">

Make sure that for each you have in your form named the way you should like:

<input name="email" />
<input name="subject" />
etc....
Daniel
  • 378
  • 1
  • 6
  • 20
  • Added that but still clicking 'submit' does nothing. – chipyzs Mar 01 '15 at 16:48
  • @chipyzs try adding method="post" to your
    tag
    – Daniel Mar 01 '15 at 16:52
  • Still not working. Don't you need a separate php send script or something like that? – chipyzs Mar 01 '15 at 16:54
  • @chipyzs Also your action will not work, you need some PHP script to get it to work, you can't just send emails like this. Look here: http://stackoverflow.com/questions/5335273/how-to-send-an-email-using-php – Daniel Mar 01 '15 at 16:54
  • Sorry for being a noob but how would I integrate that? A separate .php file or in the same file? How do I tell html to look there for the information? – chipyzs Mar 01 '15 at 16:56
  • [`mailto:` URIs are ineffective as form actions](http://isolani.co.uk/articles/mailto.html) and should not be used. That PHP code is going to turn any server it is hosted on into a spam relay. – Quentin Mar 01 '15 at 17:21
  • You've removed the bad `mailto:` advice, but the change you suggest to the button is pointless (submit is the default type) and your PHP is still a spam relay. – Quentin Mar 01 '15 at 19:45