Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Grace Mugauri
Grace Mugauri
6,398 Points

Can anyone help me fix my form its not functioning

<?php

$result="";

if (isset($_POST['submit'])){ require 'phpmailer/PHPMailerAutoload.php'; $mail = new PHPMailer;

  $mail->Host='smtp.gmail.com';
  $mail->Port=587;
  $mail->SMTPAuth=true;
  $mail->SMTPSecure=tls;
  $mail->Username='........@gmail.com';
  $mail->Password='......';

  $mail->setFrom($_POST['email'],$_POST['name']);
  $mail->addAddress('........@gmail.com');
  $mail->addReplyTo($_POST['email'],$_POST['name']);

  $mail->isHTML(true);
  $mail->Subject='Form Submission: '.$POST['subject'];
   $mail->Body='<h1 align=center>Name: '.$_POST['name']. '<br>Email: '.$_POST['email']. '<br>Subject: '.$_POST['subject']. '<br>Message: '.$_POST['message'];

if(!$mail->send()){ $result="Something went wrong. Please try again.";

} else{ $result="Thanks".$POST['name']." for contacting us. We'll get back to you soon";

}

} ?>

<!doctype html> <html lang="en">

    <div class="container bg-light">
         <div class="container bg-light">

            <h2 class="h1-responsive font-weight-bold text-center my-4">Contact us</h2>
        <p class="text-center w-responsive mx-auto mb-5">Do you have any questions? Please do not hesitate to contact us directly. Our team will come back to you within
    a matter of hours to help you.</p>


 <div class="col-md-8 col-md-offset-2 ml-5 mb-5 pl-5">

<div class=" ">
      <h5 class="text-center text-success"><?= $result; ?></h5> 
        </div>


      <form action="" method="POST">

<div class="form-group"> <label for="InputEmail">E-mail address</label> <input type="name" class="form-control" id="InputEmail" placeholder="name" name="email"> </div>

<div class="form-group">
<label for="InputName">Full name</label>
<input type="email" class="form-control" id="InputName" placeholder="email" name="email">
</div>

<div class="form-group">
<label for="InputName">Full name</label>
<input type="subject" class="form-control" id="InputName" placeholder="subject" name="subject">
</div>

<div class="form-group">
<label for="InputText">Message</label>
<textarea id="InputText" class="form-control" rows="5" placeholder="Message" name="message"></textarea>
</div>

<input type="submit" class="btn btn-default" value="Send" name="submit">

</form>

      </body>

</html>