Contact Form Help (Outside xenForo)

Brent W

Well-known member
So I am not a programmer but can find my way around code. All I want to do is have a contact form send me email.

Code:

PHP:
<?php

if ( $_GET['do'] == 'sell' ) {

    $firstName = $_POST['firstName'];
    $lastName = $_POST['lastName'];
    $email = $_POST['email'];
    $website = $_POST['url'];
    $message = $_POST['forumInfo'];
   
    //$body = "From: $firstName $lastName\n E-Mail: $email\n Message:\n $website\n $message";
    $body = 'From: ' . $firstName . ' ' . $lastName . '\n Email: ' . $email . '\n Website: ' . $website . '\n Message: ' . $message;
    $to = 'bamastangguy@gmail.com';
    $subject = 'I want To Sell My Forum';
    $from = 'website@whippmedia.com';

    if ($_POST['submit']) {
        echo($firstName);
        if ( mail($to, $subject, $body, $from) ) { 
            echo '<p>Your message has been sent!</p>';
        } else { 
            echo '<p>Something went wrong, go back and try again!</p>'; 
        }
    }

    require('./templates/sell.php');

}

?>

PHP:
<?php

// Define variables for page
$title = "Sell Your Forum - Whipp Media";

$page = 'sell';

// include header
include('./templates/header.php');

// include navigation
include('./templates/nav.php');

?>
    <div class="jumbotron">
     <div class="container">
       <div class="row">
         <div class="col-md-12">
           <h1>Sell Your Forum</h1>
           <p>We have over 10 years experience of creating and building forums. We understand that without the membership there is no forum. We engage with members to find out what they need and we put our best practices in place to help facilitate growth with each individual community. You can be certain that your forum will find a good home with us.</p>
           <p>Please use the forum below so that we can get started rewarding you for your hard work and start your forum on its next chapter in life.</p>
         </div>
        </div>
     </div>
    </div>
   
    <div class="container">
     <div class="row">
       <div class="col-md-12">   
         <form class="form-horizontal" role="form" method="post" action="contact.php?do=sell">
           <div class="form-group">
             <label for="firstName" class="col-sm-2 control-label">First Name</label>
             <div class="col-sm-10">
               <input type="text" class="form-control" id="firstName" name="firstName" placeholder="Enter First Name">
             </div>
            </div>
           
           <div class="form-group">
             <label for="lastName" class="col-sm-2 control-label">Last Name</label>
             <div class="col-sm-10">
               <input type="text" class="form-control" id="lastName" name="lastName" placeholder="Enter Last Name">
             </div>
            </div>
           
           <div class="form-group">
             <label for="email" class="col-sm-2 control-label">Email Address</label>
             <div class="col-sm-10">
               <input type="email" class="form-control" id="email" name="email" placeholder="Enter Email">
             </div>
            </div>
           
           <div class="form-group">
             <label for="url" class="col-sm-2 control-label">Website</label>
             <div class="col-sm-10">
               <input type="url" class="form-control" id="url" name="url" value="http://">
             </div>
            </div>
           
           <div class="form-group">
             <label for="forumInfo" class="col-sm-2 control-label">Forum Information</label>
             <div class="col-sm-10">
               <textarea class="form-control" id="forumInfo" name="forumInfo" rows="3"></textarea>
             </div>
            </div>
           
            <div class="form-group">
             <div class="col-sm-offset-2 col-sm-10">
               <button id="submit" name="submit" type="submit" class="btn btn-default">Submit</button>
             </div>
            </div>
         </form>
        </div>
     </div>
<?php

// include footer
include('./templates/footer.php');

?>

I can echo the variables all the way down to if ($_POST['submit']) { which is where they disappear. Nothing happens on submit. Just redirects me back to the sell page with no email sent.

What am I doing wrong?
 
change

Code:
<button id="submit" name="submit" type="submit" class="btn btn-default">Submit</button>
to
Code:
<input id="submit" name="submit" type="submit" class="btn btn-default" value="Submit" />

The button submit isn't actually an input field like input type="submit", which $_POST['submit'] is looking for.

P.S. on your "<p>" elements I would add "class='alert alert-success'" or "class='alert alert-danger'", it'll make your success message and error message look nicer to the visitor.
 
Back
Top Bottom