I wrote HTML and PHP that sends an email using a form, but the code is not working. I am getting an error message on submit, "This page isn’t working www.adurotoluwasupport.org is currently unable to handle this request. HTTP ERROR 500".
I’m not sure what I did wrong.
HTML
<div style="padding:20px" class="col-sm-7">
<h2>Become a Volunteer</h2> <br>
<form id="fcf-form-id" class="fcf-form-class" method="post" action="volunteer.php">
<div class="row cont-row">
<div class="col-sm-3"><label for="Position">Volunteer Position </label><span>:</span></div>
<div class="col-sm-8"><input type="text" id="Position" placeholder="Tell us what you are volunteering for" name="Position" class="form-control input-sm" required></div>
</div>
<div class="row cont-row">
<div class="col-sm-3"><label for="Name">Full Name </label><span>:</span></div>
<div class="col-sm-8"><input type="text" id="Name" placeholder="Enter Name" name="Name" class="form-control input-sm" pattern=[A-Zsa-z]{4,30} required></div>
</div>
<div class="row cont-row">
<div class="col-sm-3"><label for="Email">Email Address </label><span>:</span></div>
<div class="col-sm-8"><input type="email" id="Email" name="Email" placeholder="Enter Email Address" class="form-control input-sm" required></div>
</div>
<div class="row cont-row">
<div class="col-sm-3"><label for="Number">Mobile Number</label><span>:</span></div>
<div class="col-sm-8"><input type="tel" id="Number" name="Number" placeholder="Enter Mobile Number" class="form-control input-sm" required></div>
</div>
<div class="row cont-row">
<div class="col-sm-3"><label for="Address">Address </label><span>:</span></div>
<div class="col-sm-8"><input type="text" id="Address" placeholder="Your residential address" name="Address" class="form-control input-sm" required></div>
</div>
<div class="row cont-row">
<div class="col-sm-3"><label for="State">Enter State </label><span>:</span></div>
<div class="col-sm-8"><input type="text" id="State" name="State" placeholder="Your State of Residence" class="form-control input-sm" required></div>
</div>
<div class="row cont-row">
<div class="col-sm-3"><label for="Country">Enter Country</label><span>:</span></div>
<div class="col-sm-8"><input type="text" id="Country" name="Country" placeholder="Your Country of Residence" class="form-control input-sm" required></div>
</div>
<div class="row cont-row">
<div class="col-sm-3"><label for="Occupation">Occupation </label><span>:</span></div>
<div class="col-sm-8"><input type="text" id="Occupation" placeholder="Enter Occupation" name="Occupation" class="form-control input-sm" required></div>
</div>
<div class="row cont-row">
<div class="col-sm-3"><label for="Experience">Volunteer Xpernce.</label><span>:</span></div>
<div class="col-sm-8"><input type="text" id="Experience" name="Experience" placeholder="Your previous volunteer experience / Optional " class="form-control input-sm"></div>
</div>
<div class="row cont-row">
<div class="col-sm-3"><label for="Languages">Languages Spoken</label><span>:</span></div>
<div class="col-sm-8"><input type="text" id="Languages" name="Languages" placeholder="Tell us the language(s) you speak fluently" class="form-control input-sm" required></div>
</div>
<div class="row cont-row">
<div class="col-sm-3"><label for="Gender">Gender</label><span>:</span></div>
<div class="col-sm-8"><select id="Gender" name="Gender" class="form-control input-sm" required>
<option Value="">Select your Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="Other">Other</option>
</select>
</div>
</div>
<div class="row cont-row">
<div class="col-sm-3"><label for="Dob">Date of Birth</label><span>:</span></div>
<div class="col-sm-8"><input type="date" id="Dob" name="Dob" placeholder="Enter your Date of Birth" class="form-control input-sm" required></div>
</div>
<div class="row cont-row">
<div class="col-sm-3"><label for="Info">Other information</label><span>:</span></div>
<div class="col-sm-8">
<textarea rows="5" id="Info" placeholder="Enter other information that enable us make a good match" class="form-control input-sm"></textarea>
</div>
</div>
<div style="margin-top:10px;" class="row">
<div style="padding-top:10px;" class="col-sm-3"><label></label></div>
<div class="col-sm-8">
<button type="submit" id="fcf-button" class="btn btn-primary btn-sm">Submit</button>
</div>
</div>
</div>
PHP
<?php
if (isset($_POST['Email'])) {
// EDIT THE FOLLOWING TWO LINES:
$email_to = "[email protected]";
$email_subject = "Volunteer form submissions";
function problem($error)
{
echo "We're sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br><br>";
echo $error . "<br><br>";
echo "Please go back and fix these errors.<br><br>";
die();
}
// validation expected data exists
if (
!isset($_POST['Position']) ||
!isset($_POST['Name']) ||
!isset($_POST['Email']) ||
!isset($_POST['Number']) ||
!isset($_POST['Address']) ||
!isset($_POST['State']) ||
!isset($_POST['Country']) ||
!isset($_POST['Occupation']) ||
!isset($_POST['Experience']) ||
!isset($_POST['Languages']) ||
!isset($_POST['Gender']) ||
!isset($_POST['Dob']) ||
!isset($_POST['Info'])
) {
problem('We're sorry, but there appears to be a problem with the form you submitted.');
}
$position = $_POST['Position']; // required
$name = $_POST['Name']; // required
$email = $_POST['Email']; // required
$number = $_POST['Number']; // required
$address = $_POST['Address']; // required
$state = $_POST['State']; // required
$country = $_POST['Country']; // required
$occupation = $_POST['Occupation']; // required
$experience = $_POST['Experience']; //
$languages = $_POST['Languages']; // required
$gender = $_POST['Gender']; // required
$dob = $_POST['Dob']; // required
$info = $_POST['Info']; //
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
if (!preg_match($email_exp, $email)) {
$error_message .= 'The Email address you entered does not appear to be valid.<br>';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if (!preg_match($string_exp, $name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br>';
}
if (strlen($message) < 2) {
$error_message .= 'The Message you entered do not appear to be valid.<br>';
}
if (strlen($error_message) > 0) {
problem($error_message);
}
$email_message = "Form details below.nn";
function clean_string($string)
{
$bad = array("content-type", "bcc:", "to:", "cc:", "href");
return str_replace($bad, "", $string);
}
$email_message .= "Position: " . clean_string($position) . "n";
$email_message .= "Name: " . clean_string($name) . "n";
$email_message .= "Email: " . clean_string($email) . "n";
$email_message .= "Number: " . clean_string($number) . "n";
$email_message .= "Address: " . clean_string($address) . "n";
$email_message .= "State: " . clean_string($state) . "n";
$email_message .= "Country: " . clean_string($country) . "n";
$email_message .= "Occupation: " . clean_string($occupation) . "n";
$email_message .= "Experience: " . clean_string($experience) . "n";
$email_message .= "Languages: " . clean_string($languages) . "n";
$email_message .= "Gender: " . clean_string($gender) . "n";
$email_message .= "Dob: " . clean_string($dob) . "n";
$email_message .= "Info: " . clean_string($info) . "n";
// create email headers
$headers = 'From: ' . $email . "rn" .
'Reply-To: ' . $email . "rn" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- INCLUDE YOUR SUCCESS MESSAGE BELOW -->
Thanks for volunteering. We'll get back to you soon.
<?php
}
?>
2
Answers
Try this
and create php file
volunteer.php
You will see all posts inside var_dump
I think I see where your problem is:
Make sure you use the correct "" or ”.