Hi all,
I have been using a sendmail.php script for several years now without issue. All of a sudden, it is giving me a form validation message even when the specified form field is filled out. I.e., the first field is 'sender_name' and there is a validation to ensure that field is filled out. Even though it is filled out, I am getting a validation that it is blank.
I admit to being a total newbie barely know what I'm doing kind of guy. Any assistance is greately appreciated. I have searched around the forum and have found similar issues but not the same problem.
First, here's the basic form code:
<form action="sendmail.php" method="POST" language="JavaScript" name="RegistrationForm">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr>
<td width="38%">Subject:</td>
<td width="62%">
<input type="text" name="sender_subject" size="41" value="Winter 2008 BUNS on Ice Registration Request"></td>
</tr>
<tr>
<td width="38%">Name</td>
<td width="62%">
<input type="text" name="sender_name" size="20" tabindex="1"></td>
</tr>
<tr>
<td width="38%">Email</td>
<td width="62%">
<input type="text" name="sender_mail" size="20" tabindex="2"></td>
</tr>
<tr>
etc...
</form>
Here's the sendmail.php script:
<?php
include "config.php";
$date = date("l d F Y");
$time = date("g:i:s a");
$ermsg = "";
$send = 1;
if($gettheip == "yes"){
if (getenv(HTTP_X_FORWARDED_FOR)) {
$ip = getenv(HTTP_X_FORWARDED_FOR);
}
else {
$ip = getenv(REMOTE_ADDR);
}
}
function is_valid_email($sender_mail) {
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $sender_mail)) {
return 0;
}
else{
return 1;
}
}
$emailvalid = is_valid_email($sender_mail); // check email
if ($sender_name == ""){
$emsg = "Please enter your name";
$send = "0";
}
else if ($sender_mail == ""){
$emsg = "Your email address is missing";
$send = "0";
}
else if ($emailvalid == 1){
$emsg = "Your email address is incorrect";
$send = "0";
}
if($send == "0"){
$t = "$failure_title";
$msg = "$emsg, click back on your browser to complete the form!";
$s = "no";
if($default_thank_msg != "yes"){
print "$t<br><br><br>$msg";
exit;
}
}
else if($send == "1"){
$recipient = "$yourname <$email>";
$message = "Submitted: $date - $time\nFrom: $sender_name - $sender_mail\n\n\etc...";
$headers = "From: $sender_name <$sender_mail>\r\nReply-To: $sender_mail\r\n";
mail ($recipient, $sender_subject, $message, $headers);
if($auto_responder == "yes"){
$recipient2 = "$sender_name <$sender_mail>";
$subject2 = "$auto_subject to $sender_name";
$message2 = "Thank you for registering for .";
$headers2 = "From: $your_website <$email>\r\nReply-To: $email\r\n";
mail ($recipient2, $subject2, $message2, $headers2);
}
$msg = "Your message has been sent $sender_name, thank you.";
$t = "$success_title";
$s = "yes";
}
//then...
if($default_thank_msg == "yes"){
header("Location: sent.php?t=$t&msg=$msg&ip=$ip&s=$s");
exit;
}
else{
if($thankyou_message_url == ""){
header("Location: $your_webaddress");
exit;
}
else{
header("Location: $thankyou_message_url");
exit;
}
}
?>
Here's the config.php file:
<?php
$yourname = "Steve Johnson"; // Webmaster/Admin name!
$your_website = "On Ice"; // Website name!
$your_webaddress = "http://www.url.com"; // Website address including "http://" (important!)
$email = "steve@yahoo.com"; // Webmaster/Admin email address
$gettheip = "No"; // Change to "No" if you do not want the IP Address to be captured
$success_title = "Thank you!"; // Title that is displayed when the form is filled successfully
$failure_title = "Error in form!"; // Title that is displayed when a field is missed out
$auto_responder = "yes"; // Auto-respond to the sender? (set to "no" to disable)
$auto_subject = "Registration Auto Responder"; // Auto-Resonder subject line
$form_title = "Contact Us"; // Form Title (displayed on your webpage!)
$default_thank_msg = "no"; // Use the thank you message - "send.php" (set to "no" for your own, see next variable)
// Here is the confusing part....
// if you have put "no" for the above ^ variable, then declare the page you want the user to be re-directed to
// however... if nothing is put below, it will send to the homepage by default!
$thankyou_message_url = "http://url/thankyou.php"; // eg. $thankyou_message_url = "http://url/thankyou.htm";
?>
Thanks a ton!
Steve Johnson
Carmel, In
www.bunsonice.com