Topic: PHP form to email. are all fields required?
Hi, there, I recently posted a topic about my php script not working. That turned out to be a server issue after all - I had to add "ini_set()" and a -f parameter.
However I have now run across another issue. The php script will only divert to the success url, if all the form fields have been entered. If they haven't, the script will still send the email, however it wont divert to the success url. This problem I first noticed when I added the second the form to my website.
This is where it gets a little more confusing. I copied the exact code for the second php processing script, changed the form variables appropriately, changed the email address to post to, and the success page to a different url. Seemed simple enough?
Well it sends the form, but doesn't divert to the success url. I just get that damned 500 - internal error message!
Evan more weirdly (well to me) when I tried to resolve the issue, it prevented the first form from diverting altogether - despite being completely different files, variables and success urls.
So my question is, how does one allow the script to process fully, and divert without needing all the form elements to be filled? And any idea why the second form does not divert at all. I am not sure what the relationship is between the form elements and the scripts ability to divert the to the success page, yet still send the email even without all the form elements being completed!!!!!!
Any help is much appreciated!
The script code for the second form is:
<?php
/* Subject and Email Variables */
$email_to = "conceptarts@kyu-images.com";
$email_subject = "Project Mandate";
$thankyou_url = "http://www.kyu-images.com/contact-us/co
_sent.html";
/* Gathering Data Variables */
$clientnameField = $_POST["clientname"];
$businessnameField = $_POST["businessname"];
$email_from = $_POST["email"];
$phoneField = $_POST["phone"];
$address1Field = $_POST["address1"];
$address2Field = $_POST["address2"];
$townField = $_POST["town"];
$postcodeField = $_POST["postcode"];
$businessField = $_POST["business"];
$productsField = $_POST["products"];
$marketField = $_POST["market"];
$kickstartField = $_POST["kickstart"];
$photographyField = $_POST["photography"];
$termsField = $_POST["terms"];
$webdesignField = $_POST["webdesign"];
$logodesignField = $_POST["logodesign"];
$brandimageField = $_POST["brandimage"];
$mainthemeField = $_POST["maintheme"];
$styles1Field = $_POST["styles1"];
$styles2Field = $_POST["styles2"];
$styles3Field = $_POST["styles3"];
$styles4Field = $_POST["styles14"];
$registerField = $_POST["register"];
$hostingField = $_POST["hosting"];
$pagesField = $_POST["pages"];
$pagenumberField = $_POST["pagenumber"];
$galleryField = $_POST["gallery"];
$gallerynumberField = $_POST["gallerynumber"];
$formsField = $_POST["forms"];
$formnumberField = $_POST["formnumber"];
$filesField = $_POST["files"];
$filenumberField = $_POST["filenumber"];
$regionsField = $_POST["regions"];
$regionnumberField = $_POST["regionnumber"];
$animantionsField = $_POST["animantions"];
$describeField = $_POST["describe"];
$ActivEditingField = $_POST["ActivEditing"];
$databaseField = $_POST["database"];
$detailsField = $_POST["details"];
$usedwhereField = $_POST["usedwhere"];
$addtoField = $_POST["addto"];
$buildonField = $_POST["buildon"];
$purchaseothersField = $_POST["purchaseothers"];
$addprintingField = $_POST["addprinting"];
$graphicsField = $_POST["graphics"];
$dimensionsField = $_POST["dimensions"];
$boxlabeldimensionField = $_POST["boxlabeldimension"];
$headers = "From: $email_from . \r\n";
$headers .= "Reply-To: $email_from . \r\n";
$headers .= "Content-type: text/html\r\n";
$message = <<<EOD
<br><hr><br>
Client Name: $clientnameField <br>
Business Name: $businessnameField <br>
Email: $email_from <br>
Telephone: $phoneField <br>
First Address Line: $address1Field <br>
Second Address Line: $address2Field <br>
Address Town: $townField <br>
Postcode: $postcodeField <br>
<br><hr><br>
About Their Business: $businessField <br>
About Their Service/Products: $productsField <br>
About Their Target Market: $marketField <br>
Package For Kick Start Users: $kickstartField <br>
Shoot For Commercial Photography: $photographyField <br>
<br><hr><br>
Terms Agreed: $termsField <br>
<br><hr><br>
Web Design Level: $webdesignField <br>
Logo Design Level: $logodesignField <br>
Brand Image Level: $brandimageField <br>
<br><hr><br>
Main Design Theme: $mainthemeField <br>
Sub Style: $styles1Field <br>
Sub Style: $styles2Field <br>
Sub Style: $styles3Field <br>
Sub Style: $styles4Field <br>
<br><hr><br>
Register Their Site: $registerField <br>
Host Their Site: $hostingField <br>
Add Pages: $pagesField <br>
How Many: $pagenumberField <br>
Add Image Galleries: $galleryField <br>
How Many: $gallerynumberField <br>
Add Online Forms: $formsField <br>
How Many: $formnumberField <br>
Add Downloadable Files: $filesField <br>
How Many: $filenumberField <br>
Add Editable Regions: $regionsField <br>
How Many: $regionnumberField <br>
Add Animations: $animantionsField <br>
What Kind: $describeField <br>
Subscribe To ActivEditing: $ActivEditingField <br>
Create Database: $databaseField <br>
List Of Page Contents: $detailsField <br>
<br><hr><br>
Where Will The Logo Be Used: $usedwhereField <br>
Add designs to Which Services: $addtoField <br>
Build On Existing Designs: $buildonField <br>
Purchase other Concept Designs: $purchaseothersField <br>
<br><hr><br>
Additional Printing Requirements: $addprintingField <br>
What Graphics For Branding: $graphicsField <br>
Flyer, Poster Or Borchure Dimensions And Pages: $dimensionsField <br>
Box Or Label Dimensions: $boxlabeldimensionField <Br>
<br><hr><br>
<br><hr><br>
EOD;
ini_set("sendmail_from", $email_from);
$sent = mail($email_to, $email_subject, $message, $headers, "-f" . $email_from);
/*Results Rendered As HTML */
if($sent) {
header("Location: " . $thankyou_url); // Redirect customer to thankyou page
} else {
// The mail didn't send, display an error.
echo "There has been an error sending your message. Please try later.";
}
?>
