Mail form only sometimes works
Posted: Sun Jan 23, 2011 12:20 pm
Hello, this is my first post here and I'm still a bit of a noob with PHP...so go easy!
I searched as best I could for a solution to this but I haven't been too successful. I have a form and I followed some tutorials I found on other sites to validate the user supplied variables then email them. I wish I had found this site first because I think the tutorials I followed were out of date, but that's life, so I'm trying to see if I can at least get this thing to work without having to completely redo it.
The problem, as best as I can tell, is that it sometimes goes through and sometimes doesn't. I haven't been able to find a pattern either. That's what's got me so confused. If my code works, shouldn't it work every time?
I know that the "formvalidator.php" file I'm using contains some depreciated functions but it was working so I thought, if it ain't broke... Could that be causing my problems? I could post that here too, but it's pretty long so I don't know if I should just put the whole thing up or what.
You can see the form online at http://www.kreweofpetronius.org/apply. And here's the code behind it:
and then here's the actions for the form itself:
I hope this isn't information overload. I also hope this code is salvageable since I was under the assumption I was finished with this project for now.
Thank you everyone for your help. If the answer is to throw this out and start over, at least break it to me gently! lol
I searched as best I could for a solution to this but I haven't been too successful. I have a form and I followed some tutorials I found on other sites to validate the user supplied variables then email them. I wish I had found this site first because I think the tutorials I followed were out of date, but that's life, so I'm trying to see if I can at least get this thing to work without having to completely redo it.
The problem, as best as I can tell, is that it sometimes goes through and sometimes doesn't. I haven't been able to find a pattern either. That's what's got me so confused. If my code works, shouldn't it work every time?
I know that the "formvalidator.php" file I'm using contains some depreciated functions but it was working so I thought, if it ain't broke... Could that be causing my problems? I could post that here too, but it's pretty long so I don't know if I should just put the whole thing up or what.
You can see the form online at http://www.kreweofpetronius.org/apply. And here's the code behind it:
Code: Select all
<?PHP
require_once "formvalidator.php";
$show_form=true;
if(isset($_POST['submit']))
{
// Form validation:
$validator = new FormValidator();
$validator->addValidation("name","req","Please fill in your name");
$validator->addValidation("addressLine1","req","Please fill in your address");
$validator->addValidation("city","req","Please fill in city");
$validator->addValidation("state","dontselect=Select One","Please select a state");
$validator->addValidation("zipCode","req","Please enter your zip code");
$validator->addValidation("zipCode","num","Zip code should only contain numbers");
$validator->addValidation("zipCode","minlen=5","Please enter a valid, 5 digit zip code");
$validator->addValidation("phoneNum","req","Please enter a phone number");
$validator->addValidation("email","email","The input for Email should be a valid email address (ex:'name@emailprovider.com')");
$validator->addValidation("email","req","Please fill in your email");
$validator->addValidation("beMemberBecause","req","Please fill in why you would like to become a member");
$validator->addValidation("previousMember","selone","Please indicate if you have previously been a member of the Krewe of Petronius or another Gay Mardi Gras Organization");
$validator->addValidation("agreeToTerms","shouldselchk=yes","You must check the box to indicate you agree to the terms of this application.");
//User supplied variables:
$applicantName = $_POST["name"];
$addressLine1 = $_POST["addressLine1"];
$addressLine2 = $_POST["addressLine2"];
$city = $_POST["city"];
$state = $_POST["state"];
$zipCode = $_POST["zipCode"];
$homePhone = $_POST["phoneNum"];
$cellPhone = $_POST["phoneNumCell"];
$applicantEmail = $_POST["email"];
$beMemberBecause = $_POST["beMemberBecause"];
$previousMember = $_POST["previousMember"];
$whyLeftPrevious = $_POST["whyLeftPrevious"];
$specialSkills = $_POST["specialSkills"];
$agreeToTerms = $_POST["agreeToTerms"];
$sponser1 = $_POST["sponser1"];
$sponser2 = $_POST["sponser2"];
$sponser3 = $_POST["sponser3"];
$sponser4 = $_POST["sponser4"];
$sponser5 = $_POST["sponser5"];
if($validator->ValidateForm())
{
// successful submit actions
//$recipient = "applications@kreweofpetronius.org"; //email for the organization
$recipient = "xxxx@gmail.com"; //my email for testing
$emailText =
"$applicantName has submitted an online application. Here is their information:\n\n".
"Name: $applicantName \n".
"Address: $addressLine1 \n".
"$addressLine2 \n".
"$city, $state $zipCode \n".
"Phone: $homePhone \n".
"Cell Phone: $cellPhone \n".
"Email: $applicantEmail \n".
"I would like to become a member of the Krewe of Petronius because: $beMemberBecause \n".
"Have you ever been a member of the Krewe of Petronius or any other gay Mardi Gras Organization?: $previousMember \n".
"If yes which one and why did you leave?: $whyLeftPrevious \n".
"If accepted into the Krewe, what special skills do you bring to the Krewe?: $specialSkills \n".
"I agree to the terms of the application: $agreeToTerms \n".
"Sponsers: \n
$sponser1 \n
$sponser2 \n
$sponser3 \n
$sponser4 \n
$sponser5 \n".
"\n -------------------------------------- \n".
"If you are experiencing any problems with form submissions, please contact me";
mail($recipient, "Online application from kreweofpetronius.org", $emailText);
$show_form=false;
echo "Thank you, your application has been submited.<br />";
echo "Questions? Contact applications@kreweofpetronius.org<br />";
echo "Please <a href='http://www.shop.kreweofpetronius.org/Donate-50-to-Support-Krewe-of-Petronius-donate.htm'>click here</a> to submit your application fee online.<br />";
}
else
{
echo "<B>The following problems were encountered with your submission:</B>";
$error_hash = $validator->GetErrors();
foreach($error_hash as $inpname => $inp_err)
{
echo "<p>$inp_err</p>\n";
}
}
}
if(true == $show_form)
{
?>Code: Select all
<form id="ApplicationForm" name="ApplicationForm" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>">Thank you everyone for your help. If the answer is to throw this out and start over, at least break it to me gently! lol