I got an html template with a contact form from a site and I love it. I edited it to send the data to me, and it works. Once the user hits submit, the alert-box comes across the page indicating the message was sent. I need another form so I copied the original one, changed the name, edited the forms with the fields I need, copied the php file to one with a name that corresponds to my new form. The form works, I get the data however, instead of getting the alert-box, the page goes to a blank page with the url of the php file and the message "Thank you! We have received your message." I don't know what's wrong and why the alert box isn't working. Any help would be appreciated.
<?php
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$full_name = ($_GET['full_name']) ? $_GET['full_name'] : $_POST['full_name'];
$h_address = ($_GET['h_address']) ?$_GET['h_address'] : $_POST['h_address'];
$h_city = ($_GET['h_city']) ?$_GET['h_city'] : $_POST['h_city'];
$h_state = ($_GET['h_state']) ?$_GET['h_state'] : $_POST['h_state'];
$h_zipcode = ($_GET['h_zipcode']) ?$_GET['h_zipcode'] : $_POST['h_zipcode'];
$h_phone_n = ($_GET['h_phone_n']) ?$_GET['h_phone_n'] : $_POST['h_phone_n'];
$c_phone_n = ($_GET['c_phone_n']) ?$_GET['c_phone_n'] : $_POST['c_phone_n'];
$h_email = ($_GET['h_email']) ?$_GET['h_email'] : $_POST['h_email'];
$w_fon_n1 = ($_GET['w_fon_n1']) ?$_GET['w_fon_n1'] : $_POST['w_fon_n1'];
$w_email = ($_GET['w_email']) ?$_GET['w_email'] : $_POST['w_email'];
$Voice = ($_GET['Voice']) ?$_GET['Voice'] : $_POST['Voice'];
$First_Second = ($_GET['First_Second']) ?$_GET['First_Second'] : $_POST['First_Second'];
$notify_by = ($_GET['notify_by']) ?$_GET['notify_by'] : $_POST['notify_by'];
$Experience = ($_GET['Experience']) ?$_GET['Experience'] : $_POST['Experience'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//Simple server side validation for POST data, of course, you should validate the email
if (!$full_name) $errors[count($errors)] = 'Please enter your full name.';
if (!$h_address) $errors[count($errors)] = 'Please enter your street address.';
if (!$h_city) $errors[count($errors)] = 'Please enter your city.';
if (!$h_state) $errors[count($errors)] = 'Please enter your state.';
if (!$h_zipcode) $errors[count($errors)] = 'Please enter your zipcode.';
if (!$h_phone_n) $errors[count($errors)] = 'Please enter your home phone.';
if (!$c_phone_n) $errors[count($errors)] = 'Please enter your cell phone.';
if (!$h_email) $errors[count($errors)] = 'Please enter your email.';
if (!$Voice) $errors[count($errors)] = 'Please enter your voice part.';
if (!$First_Second) $errors[count($errors)] = 'Please enter whether first or second.';
if (!notify_by) $errors[count($errors)] = 'Please enter how we should contact you.';
if (!$Experience) $errors[count($errors)] = 'Please enter your choral experience.';
//if the errors array is empty, send the mail
if (!$errors) {
//recipient - replace your email here
$to = 'mail@email.com';
//sender - from the form
$from = 'MCC Audition Request <webmaster@mendelssohnchoir.com>';
//subject and the html message
$subject = 'MCC Audition Request from ' . $full_name;
$message = 'FullName: ' . $full_name . '<br/><br/>
Address: ' . $h_address . '<br/><br/>
City: ' . $h_city . '<br/><br/>
State: ' . $h_state . '<br/><br/>
Zipcode: ' . $h_zipcode . '<br/><br/>
HPhone: ' . $h_phone_n . '<br/><br/>
HCell: ' . $c_phone_n . '<br/><br/>
HomeEmail: ' . $h_email . '<br/><br/>
WPhone: ' . $w_phone_n . '<br/><br/>
WEmail: ' . $w_email . '<br/><br/>
Voice: ' . $Voice . '<br/><br/>
Voicepart: ' . $First_Second . '<br/><br/>
NotifyBy: ' . $notify_by . '<br/><br/>
Message: ' . nl2br($Experience) . '<br/>';
//send the mail
$result = sendmail($to, $subject, $message, $from);
//if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! We have received your message.';
else echo 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
echo $result;
}
//if the errors array has values
} else {
//display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
echo '<a href="index.html">Back</a>';
exit;
}
//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
?>