Reputation: 9
Here's my HTML code:
<form method="POST" action="thank_you.php" novalidate>
<div class="form-group">
<label for="name">Full Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name" required>
<div class="valid-feedback">Looks good</div>
<div class="invalid-feedback">Please enter your name</div>
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="eg: [email protected]" required>
</div>
<div class="form-group">
<label for="url">Your Website</label>
<input type="text" class="form-control" id="url" name="url" placeholder="eg: www.website.com">
</div>
<h4>Project Details</h4>
<p>Please provide a brief description of your project, what your end goal is, and how I can help you achieve this goal.
Please, also specify what your budget is.</p>
<div class="form-group">
<label for="budget">Budget Amount</label>
<input type="text" class="form-control" id="budget" name="budget" placeholder="eg: $2,000" required>
</div>
<div class="form-group">
<label for="project">Project Description</label>
<textarea class="form-control" id="project" name="project" rows="5" required></textarea>
</div>
<div class="form-group">
<label for="completion">Desired Completion Date</label>
<select class="form-control" id="completion" name="completion" required>
<option>Please select</option>
<option>As soon as possible</option>
<option>1-3 weeks</option>
<option>1-3 months</option>
<option>4-6 months</option>
<option>To be determined</option>
</select>
</div>
<button type="submit" class="btn btn-primary" name="submit">SEND</button>
</form>
And here's my PHP:
$name = $_POST['name'];
$email = $_POST['email'];
$url = $_POST['url'];
$budget = $_POST['budget'];
$project = $_POST['project'];
$completion = $_POST['completion'];
$to = "[email protected]";
$subject = "New Request";
$body = "Please see details below.";
mail($to, $subject, $body);
?>
What happens is once the form is submitted, only everything in the mail(function) displays, but not the input one. So Can somebody please show me where I went wrong and how I can fix it?
Upvotes: 0
Views: 97
Reputation: 1167
Currently your code is incomplete, You should include the submission data to $body
like this:
$body = "Please see details below.";
$body .= '\r\n Name :'.$name.'\r\n';
$body .= '\r\n Email :'.$email.'\r\n';
also the option tag must have a value attribute
<select class="form-control" id="completion" name="completion" required>
<option value="">Please select</option>
<option value="As soon as possible">As soon as possible</option>
<option value="1-3 weeks">1-3 weeks</option>
<option value="1-3 months">1-3 months</option>
<option value="4-6 months">4-6 months</option>
<option value="To be determined">To be determined</option>
</select>
Upvotes: 4
Reputation: 4033
You have to pass POST data into $body tag for example :
$to = "[email protected]";
$subject = "New Request";
$body = "";
$name = $_POST['name'];
$email = $_POST['email'];
$url = $_POST['url'];
$budget = $_POST['budget'];
$project = $_POST['project'];
$completion = $_POST['completion'];
$body = "Hello ". $name."," .'<br/>';
$body .= $email;
$body .= "Your bugdet is :" . $budget;
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
mail($to,$subject,$body,$headers);
Upvotes: 0