-1

I need help with my Contact Form coding. I am working on a Dreamweaver CS6 website. Could you take a look at my code and see what is wrong with it? I think, the html is fully correct. There is an error on php coding.

Html:

  <form action="assets/styles/contact_form.php" method="post" class="ui-form form-contacts">
    <div class="container">
      <div class="row">
        <div class="col-xs-12">
          <h2 class="ui-title-block">Get In Touch</h2>
          <div class="ui-subtitle-block">send us a message</div>
          <div class="border-color border-color_center"></div>
        </div>
      </div>
      <div class="row">
        <div class="col-sm-4 col-sm-offset-1">
          <div class="input-group">
            <input type="text" placeholder="NAME" name="author" required class="form-control">
          </div>
          <div class="input-group">
            <input type="email" name="email" required placeholder="EMAIL" class="form-control">
          </div>
          <div class="input-group">
            <input type="text" name="subject" placeholder="SUBJECT" class="form-control">
          </div>
        </div>
        <div class="col-sm-6">
          <div class="input-group">
            <textarea id="comment-text" name="comment" placeholder="COMMENT" required rows="9" class="form-control"></textarea>
          </div>
          <div class="text-right">
            <button class="btn">SEND<i class="icon fa fa-angle-double-right"></i> </button>
          </div>
        </div>
      </div>
    </div>
  </form>

Php:

<?php
if(isset($_POST['user_name'])){
$author         = $_POST['user_name'];
$email      = $_POST['user_email'];
$to         = 'john@mybusiness.ca';
$subject    = $_POST['message_subject'];
$comment    = $_POST['message_content'];
$headers    = 'From: '. $author .' <'.$email.'>';

if(mail($to, $subject, $message, $headers)){
    echo 'success';
}
else{
    echo 'fail';
}
}
?>
SHE
  • 3
  • 3

1 Answers1

2

It's just a common thing. The name attribute you are using in your html code is not been used to get the value using post associative array. The value of input submitted by the from can only be extracted through a unique id or text. This is for what name attribute is used. Now to get the value we can use $_POST associative array and point to our input value by giving it the name attribute that we gave it in the previous page(html form). I hope i made my point clear. If you need some more assistant try to go to this link http://php.net/manual/en/reserved.variables.post.php. Try this code

<?php
if(isset($_POST['author'])){
$author         = $_POST['author'];
$email      = $_POST['email'];
$to         = 'john@mybusiness.ca';
$subject    = $_POST['subject'];
$comment    = $_POST['comment'];
$headers    = 'From: '. $author .' <'.$email.'>';

if(mail($to, $subject, $message, $headers)){
    echo 'success';
}
else{
    echo 'fail';
}
}
?>

Hope this helps you

Utkarsh Dixit
  • 4,267
  • 3
  • 15
  • 38