I have made a web form that sends an email with the form information contained within. I have a couple of issues I haven't been able to fix though, and I am hoping someone can help.
- The selection boxes for Current Club Membership do not return any information in the email, just a blank space where the information should be, even though an option is selected.
- After the form is sent the mail.php file loads. I would like a thank you HTML page to load instead. How do I do that? I tried changing the action attribute in the HTML to the page I want, but then the email doesn't send.
The HTML:
<form method="post" action="mail.php">
<div class="row uniform">
<div class="6u 12u$(xsmall)">
<label for="name">Full Name</label>
<input name="name" type="text" class="required" id="name" value="" />
</div>
<div class="6u$ 12u$(xsmall)">
<label for="email">Email Address</label>
<input name="email" type="email" class="required" id="email" value="" />
</div>
<div class="6u 12u$(xsmall)">
<label for="date">Date of Birth</label>
<input name="date" type="text" class="required" id="date" value="" />
</div>
<div class="6u$ 12u$(xsmall)">
<label for="age">Age as of July 1, 2016</label>
<input name="age" type="text" class="required" id="age" value="" />
</div>
<div class="6u 12u$(xsmall)">
<label for="phone">Phone Number</label>
<input name="phone" type="tel" class="required" id="phone" value="" />
</div>
<div class="12u$">
<label for="club">Current Club Membership</label>
<div class="select-wrapper">
<select name="club" class="required" id="club">
<option value="">-</option>
<option value="Colonial Road Runners">Colonial Road Runners</option>
<option value="Peninsula Track Club">Peninsula Track Club</option>
<option value="Tidewater Striders">Tidewater Striders</option>
</select>
</div>
</div>
<div class="12u$">
<label for="message">Message</label>
<textarea name="message" id="message" rows="6"></textarea>
</div>
<div class="12u$">
<ul class="actions">
<li><input type="submit" name="submit" value="Send Message" class="special" /></li>
<li><input type="reset" value="Reset" /></li>
</ul>
</div>
</div>
</form>
The php:
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$date = $_POST['date'];
$age = $_POST['age'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$from = 'From: hrsupergp@gmail.com';
$to = '6linewrasse@gmail.com';
$subject = 'New Registration';
$body.='email: '. $_POST['email']."\n";
$body.='date: '. $_POST['date']."\n";
$body.='age: '. $_POST['age']."\n";
$body.='phone: '. $_POST['phone']."\n";
$body.='club: '. $_POST['club']."\n";
$body = "From: $name
E-Mail: $email
Date: $date
Age 7/2016: $age
Phone: $phone
Club: $club
Message: $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
?>